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
#include <iostream>
using namespace std;

int t, k, n, arr[22][22], roundCount, sum;

int main() {
	ios_base::sync_with_stdio(0);
	cin >> t >> k;
	while (t--) {
		cin >> n;
		for (int y = 0; y < n; y++) {
			for (int x = 0; x < n; x++) {
				cin >> arr[y][x];
				sum += (arr[y][x] + 9) / 10;
			}
		}
		cout << "R FARMER\n";
		int y = 0, x = 0;
		bool up = 0;
		while (y != 0 || x != n - 1) {
			if (arr[y][x] > 0) {
				arr[y][x] = arr[y][x] > 10 ? arr[y][x] - 10 : 0;
			} else {
				if (up && y > 0) {
					cout << "M " << y << " " << x << " " << y - 1 << " " << x << "\n";
					y--;
				} else if (up && y == 0) {
					cout << "M " << y << " " << x << " " << y << " " << x + 1 << "\n";
					x++;
					up = 0;
				} else if (!up && y < n - 1) {
					cout << "M " << y << " " << x << " " << y + 1 << " " << x << "\n";
					y++;
				} else if (!up && y == n - 1) {
					cout << "M " << y << " " << x << " " << y << " " << x + 1 << "\n";
					x++;
					up = 1;
				}
				arr[y][x] = arr[y][x] > 10 ? arr[y][x] - 10 : 0;
			}
			cout << "=\n";
			roundCount++;
		}
		while (arr[y][x] > 0) {
			arr[y][x] = arr[y][x] > 10 ? arr[y][x] - 10 : 0;
			cout << "=\n";
		}
		while (x > 0) {
			cout << "M " << y << " " << x << " " << y << " " << x - 1 << "\n=\n";
			x--;
			roundCount++;
		}
		cout << "===\n";
		roundCount++;
	}
}