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
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 20;
int t[MAXN+5][MAXN+5];

void query(void){
	int n;
	cin >> n;

	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin >> t[i][j];

	pair<int,int> a(0,1), b(1,0);
	int x=0, y=0;

	cout << "R FARMER\n";
	cout << "M 0 0 0 1\n";
	cout << "R FARMER\n";
	cout << "M 0 0 1 0\n";
	cout << "=\n";

	while(x != 1 || y != 1){
		if(t[a.first][a.second] > 0)
			t[a.first][a.second] -= min(10, t[a.first][a.second]);
		else{
			if(a == make_pair(19,1))
				x = 1;
			else if(a.first%4 == 0 && a.second != 19){
				cout << "M " << a.first << " " << a.second << " " << a.first << " " << a.second+1 << "\n";
				a.second++;
			}else if(a.first%4 == 3 && a.second != 1){
				cout << "M " << a.first << " " << a.second << " " << a.first << " " << a.second-1 << "\n";
				a.second--;
			}else{
				cout << "M " << a.first << " " << a.second << " " << a.first+1 << " " << a.second << "\n";
				a.first++;
			}

			t[a.first][a.second] -= min(10, t[a.first][a.second]);
		}

		if(t[b.first][b.second] != 0)
			t[b.first][b.second] -= min(10, t[b.first][b.second]);
		else{
			if(b == make_pair(19,0))
				y = 1;
			else if(b.first%4 == 1 && b.second != 18){
				cout << "M " << b.first << " " << b.second << " " << b.first << " " << b.second+1 << "\n";
				b.second++;
			}else if(b.first%4 == 2 && b.second != 0){
				cout << "M " << b.first << " " << b.second << " " << b.first << " " << b.second-1 << "\n";
				b.second--;
			}else{
				cout << "M " << b.first << " " << b.second << " " << b.first+1 << " " << b.second << "\n";
				b.first++;
			}

			t[b.first][b.second] -= min(10, t[b.first][b.second]);
		}

		cout << "=\n";
	}

	while(a.first != 0){
		cout << "M " << a.first << " " << a.second << " " << a.first-1 << " " << a.second << "\n";
		cout << "M " << b.first << " " << b.second << " " << b.first-1 << " " << b.second << "\n";
		a.first--;
		b.first--;
		cout << "=\n";
	}

	cout << "M 0 0 1 0\n";
	cout << "M 0 1 0 0\n";
	cout << "=\n";
	cout << "===\n";
}

int main(void){
	ios_base::sync_with_stdio(false);
	int q,k;
	cin >> q >> k;

	while(q--)
		query();

	return 0;
}