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
#include <iostream>
#include <vector>
#include <algorithm>

typedef std::pair<int, int> PI;

int b[20][20];

void move(PI s, PI d) {
    std::cout <<  "M " << s.first <<  " " << s.second <<  " " << d.first << " " << d.second << std::endl;
}

int main() {
    int T, n, k;
    bool brick = false;
    std::cin >> T >> k;
    while (T--) {
        std::cin >> n;
        for (int i = 0 ; i < n ; i++) {
            for (int j = 0 ; j < n ; j++) {
                std::cin >> b[i][j];
                if (b[i][j] < 0) {
                    brick = true;
                }
            }
        }
        if (brick) {
            std::vector<PI> path_tank;
            path_tank.push_back(PI(0, 0));
            for (int r = 0 ; r < n ; r++) {
                if (r % 2 == 0) {
                    for (int c = 1 ; c < n ; c++) {
                        path_tank.push_back(PI(r, c));
                    }
                } else {
                    for (int c = n - 1 ; c >= 1 ; c-- ) {
                        path_tank.push_back(PI(r, c));
                    }
                }
            }
            for (int r = n - 1 ; r >= 0 ; r --) {
                path_tank.push_back(PI(r, 0));
            }
            path_tank.push_back(PI(0, 1));
            std::cout << "R TANK\nM 0 0 0 1\nR FARMER\n=\n";
            for (int i = 0 ; i < path_tank.size() - 2 ; i++) {
                move(path_tank[i + 1], path_tank[i + 2]); //tank
                move(path_tank[i], path_tank[i + 1]); // farmer
                if (i != path_tank.size() - 3) {
                    std::cout << "=\n";
                }
            }
        } else {
            std::cout << "R FARMER\nM 0 0 0 1\nR FARMER\nM 0 0 1 0\n=\n";
            std::vector<PI> farmer1, farmer2;
            farmer1.push_back(PI(0, 0));
            for (int c = 0 ; c <= n / 2 ; c++) {
                farmer2.push_back(PI(0, c));
            }
            for (int c = 0 ; c < n / 2 ; c++) {
                if (c % 2 == 0) {
                    for (int r = 1 ; r < n ; r++){
                        farmer1.push_back(PI(r, c));
                        farmer2.push_back(PI(r, c + n/2));
                    }
                } else {
                    for (int r = n - 1 ; r >= 1 ; r--){
                        farmer1.push_back(PI(r, c));
                        farmer2.push_back(PI(r, c + n/2));
                    }
                }
            }
            for (int c = n / 2 - 1 ; c >= 0 ; c--) {
                farmer1.push_back(PI(0, c));
            }
            farmer1.push_back(PI(1, 0));
            for (int c = n - 1 ; c >= 0 ; c--) {
                farmer2.push_back(PI(0, c));
            }
            for (int i = 0 ; i < farmer2.size() - 1 ; i++) {
                if (i < farmer1.size() - 1) {
                    move(farmer1[i], farmer1[i + 1]);
                }
                move(farmer2[i], farmer2[i + 1]);
                if (i != farmer2.size() - 2) {
                    std::cout << "=\n";
                }
            }
        }
        std::cout << "===\n";
    }
}