1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <bits/stdc++.h>

using namespace std;
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PI; 
typedef pair<LL,LL> PLL;
typedef unsigned long long ULL;
typedef pair<double,double> PD;

#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())

#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000011
#define MOD 1000000007

#define MAXSIZE 410
#define MAX_T 30

int mapa[MAX_T][MAX_T];
int zaj[MAX_T][MAX_T];

PI poz[MAXSIZE];
int plec[MAXSIZE];

int t,k,n;

int zloto=200;
int t_sum=0;
int kolejki=0;
int ile=0;

void end_t(){
	
	REP(i,n){
		REP(j,n){
			if(zaj[i][j]!=0){
				plec[zaj[i][j]]+=min(10,mapa[i][j]);
				mapa[i][j]=max(0,mapa[i][j]-10);
			}
		}
	}
	
	if(zaj[0][0]!=0){
		if(zaj[0][0]==1)
			kolejki++;

		zloto+=plec[zaj[0][0]];
		t_sum+=plec[zaj[0][0]];
		plec[zaj[0][0]]=0;
	}
	
	cout<<"=\n";
}

void move(){
	PI cat;
	if(kolejki==0||kolejki==2){
		if(poz[1].ND==0){
			if(poz[1].ST==19)
				cat={19,1};
			else
				cat={poz[1].ST+1,0};
		}
		else{
			if(poz[1].ST==0)
				cat={0,0};
			else
				cat={poz[1].ST-1,1};
		}
	}
	else if(kolejki==1){
		if(poz[1].ST==1){
			if(poz[1].ND==19)
				cat={0,19};
			else
				cat={1,poz[1].ND+1};
		}
		else{
			if(poz[1].ND==0)
				cat={1,0};
			else
				cat={0,poz[1].ND-1};
		}
	}
	else{
		if(poz[1].ST==0){
			if(poz[1].ND==0)
				cat={1,0};
			else
				cat={0,poz[1].ND-1};
		}
		else if(poz[1].ND==19){
			cat={poz[1].ST-1,19};
		}
		else if(poz[1].ST==1){
			if(poz[1].ND%2==0)
				cat={2,poz[1].ND};
			else
				cat={1,poz[1].ND+1};
		}
		else if(poz[1].ST==19){
			if(poz[1].ND%2==0)
				cat={19,poz[1].ND+1};
			else
				cat={18,poz[1].ND};
		}
		else{
			if(poz[1].ND%2==0)
				cat={poz[1].ST+1,poz[1].ND};
			else
				cat={poz[1].ST-1,poz[1].ND};
		}
	}
	
	zaj[poz[ile].ST][poz[ile].ND]=0;
	vector<PI> bufor;
	FORD(i,ile,2){
		bufor.PB({poz[i].ST,poz[i].ND});
		poz[i]=poz[i-1];
		zaj[poz[i].ST][poz[i].ND]=i;
		bufor.PB({poz[i].ST,poz[i].ND});
	}
	
	bufor.PB({poz[1].ST,poz[1].ND});
	poz[1]=cat;
	bufor.PB({poz[1].ST,poz[1].ND});
	zaj[cat.ST][cat.ND]=1;
	
	for(int i=SIZE(bufor)-1;i>=0;i-=2)
		cout<<"M "<<bufor[i-1].ST<<" "<<bufor[i-1].ND<<" "<<bufor[i].ST<<" "<<bufor[i].ND<<"\n";
	
}

void reset(){
	zloto=200;
	t_sum=0;
	kolejki=0;
	ile=0;
	
	REP(i,MAX_T){
		REP(j,MAX_T){
			mapa[i][j]=0;
			zaj[i][j]=0;
		}
	}
	REP(i,MAXSIZE){
		poz[i]={0,0};
		plec[i]=0;
	}
}

void rent(){
	zloto-=100;
	ile++;
	poz[ile]={0,0};
	zaj[0][0]=ile;
	cout<<"R FARMER\n";
}

int main(){
	
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>t>>k;
	
	
	REP(I,t){
		
		int suma=0;
		cin>>n;
		REP(i,n){
			REP(j,n){
				cin>>mapa[i][j];
				suma+=mapa[i][j];
			}
		}
		
		while(t_sum<suma){
			if(zaj[0][0]==0&&zaj[0][1]==0&&zaj[1][0]==ile&&zloto-100>=0&&ile<=51)
				rent();
			
			move();
			end_t();
		}
		
		reset();
		
		cout<<"===\n";
	}
	
	
	return 0;
}