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
201
202
203
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
const int mod=1000000007,mxn=1000010;
struct far{
	int x;
	int y;
	int gold;
	int dobazy;
};
int pla[30][30];
int gold,n,wog=0;
int zaj[30][30],rob;
vector<far> pos;
void kontu(){
	cout <<"=\n";
	for(int i=0;i<pos.size();i++){
		int x=pos[i].x;
		int y=pos[i].y;
		int zy=min(pla[x][y],10);
		pos[i].gold+=zy;
		pla[x][y]-=zy;
		wog-=zy;
		if(x==0 && y==0){
			gold+=pos[i].gold;
			pos[i].gold=0;
		}
	}
}
int alejk(){
	for(int i=0;i<n;i++){
		if(zaj[0][i]){
			return 0;
		}
	}
	return 1;
}
void rek(){
	far now;
	now.x=0;
	now.y=0;
	now.gold=0;
	now.dobazy=0;
	pos.pb(now);
	gold-=100;
	zaj[0][0]=1;
	cout <<"R FARMER\n";
}
int chce(){
	int ter=pos.size();
	int tug=gold;
	for(int i=0;i<pos.size();i++){
		if(pos[i].dobazy){
			tug+=pos[i].gold;
		}
	}
	ter+=tug/100;
	if(ter<n){
		return 1;
	}
	return 0;
}
void rusz(far& f,int kt){
	if(f.x==0 && f.y==0){
		f.dobazy=0;
	}
	if(pos.size()==n){
		f.dobazy=0;
	}
	if(f.dobazy==1){
		if(f.x==0){
			cout <<"M "<<0 <<" "<<f.y <<" "<<0 <<" "<<f.y-1<<"\n";
			zaj[f.x][f.y]=0;
			f.y--;
			zaj[f.x][f.y]=1;
			return;
		}
		if(f.x>1 || (f.x==1 && alejk() ) ){
			cout <<"M "<<f.x <<" "<<f.y <<" "<<f.x-1 <<" "<<f.y<<"\n";
			zaj[f.x][f.y]=0;
			f.x--;
			zaj[f.x][f.y]=1;	
			return;
		}
		else{
			return;
		}
	}
	if(f.gold>=100 && chce()){
		f.dobazy=1;
	}
	if(f.y!=kt){
		cout <<"M "<<f.x <<" "<<f.y <<" "<<f.x <<" "<<f.y+1 <<"\n";
		zaj[f.x][f.y]=0;
		f.y++;
		zaj[f.x][f.y]=1;
		return;
	}
	if(f.x==0){
		cout <<"M "<<f.x <<" "<<f.y <<" "<<f.x+1 <<" "<<f.y<<"\n";
		zaj[f.x][f.y]=0;
		f.x++;
		zaj[f.x][f.y]=1;
		return;
	}
	if(pla[f.x][f.y]==0 && f.x!=n-1){
		cout <<"M "<<f.x <<" "<<f.y <<" "<<f.x+1 <<" "<<f.y<<"\n";
		zaj[f.x][f.y]=0;
		f.x++;
		zaj[f.x][f.y]=1;
		return;
	}
	return;	
}
void tura(){
	if(pos.size()<n && alejk() && gold>=100){
		rek();
	}
	for(int i=0;i<pos.size();i++){
		rusz(pos[i],i);
	}
}
int zeb(){
	for(int i=1;i<n;i++){
		for(int j=0;j<n;j++){
			if(pla[i][j]){
				return 1;
			}
		}
	}
	return 0;
}
int gdzi(){
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(pla[i][j]){
				return 1;
			}
		}
	}
	return 0;
}
void kon(){
	//cout <<"TU koniec\n";
	while(gdzi()){
		for(int i=0;i<pos.size();i++){
			if(pos[i].x!=0){
				cout <<"M "<<pos[i].x <<" "<<pos[i].y <<" "<<pos[i].x-1 <<" "<<pos[i].y <<"\n";
				pos[i].x--;
			}
		}
		kontu();
	}
	for(int i=0;i<n-1;i++){
		for(int j=0;j<n;j++){
			if(pos[j].y==0){
				cout <<"M "<<pos[j].x <<" "<<pos[j].y <<" "<<pos[j].x+1 <<" "<<pos[j].y <<"\n";
				pos[j].x++;
			}
			else{
				cout <<"M "<<pos[j].x <<" "<<pos[j].y <<" "<<pos[j].x <<" "<<pos[j].y-1 <<"\n";
				pos[j].y--;
			}
		}
		kontu();
	}
}
void test(){
	cin >>n;
	gold=200;
	rob=0;
	wog=0;
	pos.clear();
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin >>pla[i][j];
			zaj[j][i]=0;
		}
	}
	while(pos.size()<n || zeb()){
		tura();
		kontu();
	}
	kon();
	cout <<"===\n";
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int z,limit;
	cin >>z >>limit;
	while(z--){
		test();
	}
}