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

const int maxN = 20;
int N;
int arr[maxN][maxN];

void step1() {
    int posX = 0, posY = 0;
    int sum = 100;
    cout<<"R FARMER"<<endl;
    while (sum < (N - 1) * 100) {
        if (arr[posX][posY] == 0) {
            if (posY % 2 == 0) {
                if (posX < N - 1) {
                    cout<<"M "<<posX<<' '<<posY<<' '<<posX + 1<<' '<<posY<<endl;
                    ++posX;
                }
                else {
                    cout<<"M "<<posX<<' '<<posY<<' '<<posX<<' '<<posY + 1<<endl;
                    ++posY;
                }
            }
            else {
                if (posX > 0) {
                    cout<<"M "<<posX<<' '<<posY<<' '<<posX - 1<<' '<<posY<<endl;
                    --posX;
                }
                else {
                    cout<<"M "<<posX<<' '<<posY<<' '<<posX<<' '<<posY + 1<<endl;
                    ++posY;
                }
            }
        }
        sum += min(arr[posX][posY], 10);
        arr[posX][posY] = max(arr[posX][posY] - 10, 0);
        cout<<"="<<endl;
    }
    while (posX > 0) {
        cout<<"M "<<posX<<' '<<posY<<' '<<posX - 1<<' '<<posY<<endl;
        --posX;
        cout<<"="<<endl;
    }
    while (posY > 0) {
        cout<<"M "<<posX<<' '<<posY<<' '<<posX<<' '<<posY - 1<<endl;
        --posY;
        cout<<"="<<endl;
    }
}

void step2() {
    for (int i = 0; i < N - 1; ++i) {
        for (int j = i; j >= 0; --j) {
            cout<<"M "<<0<<' '<<j<<' '<<0<<' '<<j + 1<<endl;
        }
        cout<<"R FARMER"<<endl;
        cout<<"="<<endl;
    }
}

void step3() {
    int row[maxN] = {0};
    int ready = 0;
    bool isReady[maxN] = {false};
    while (ready < N) {
        for (int i = 0; i < N; ++i) {
            if (arr[row[i]][i] == 0) {
                if (row[i] == N - 1) {
                    if (!isReady[i]) {
                        ++ready;
                        isReady[i] = true;
                    }
                }
                else {
                    cout<<"M "<<row[i]<<' '<<i<<' '<<row[i] + 1<<' '<<i<<endl;
                    ++row[i];
                }
            }
        }
        for (int i = 0; i < N; ++i) {
            arr[row[i]][i] = max(arr[row[i]][i] - 10, 0);
        }
        cout<<"="<<endl;
    }
}

void step4() {
    for (int i = N - 1; i > 0; --i) {
        for (int j = 0; j < N; ++j) {
            cout<<"M "<<i<<' '<<j<<' '<<i - 1<<' '<<j<<endl;
        }
        cout<<"="<<endl;
    }
    for (int i = 0; i < N - 1; ++i) {
        for (int j = i; j >= 0; --j) {
            cout<<"M "<<j<<' '<<0<<' '<<j + 1<<' '<<0<<endl;
        }
        for (int j = 1; j < N - i; ++j) {
            cout<<"M "<<0<<' '<<j<<' '<<0<<' '<<j - 1<<endl;
        }
        cout<<"="<<endl;
    }
    cout<<"==="<<endl;
}

int main() {
    int z, k;
    cin>>z>>k;
    while (z--) {
        cin>>N;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                cin>>arr[i][j];
            }
        }
        step1();
        step2();
        step3();
        step4();
    }
    return 0;
}