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

#define rep(a,b,c) for(auto a = (b); a != (c); a++)
#define repD(a,b,c) for(auto a = (b); a != (c); a--)
#define repIn(a, b) for(auto& a : (b))
#define repIn2(a, b, c) for(auto& [a, b] : (c))

constexpr bool dbg = 0;
#define DEBUG if constexpr(dbg)
#define DC DEBUG std::cerr
#define eol std::endl

#define int long long
#define ld long double
#define pb push_back

using namespace std;
#define rg ranges

mt19937 rnd;

void encode() {
    int n, t;
    cin >> n >> t;
    while(t--) {
        int xr = rnd() % n + 1;
        int x;
        cin >> x;
        x ^= xr;
        rep(i, 0, 7) {
            rep(j, 0, 5) cout << x % 2, x /= 2;
            rep(j, 0, 3) cout << (i & (1 << j));
            cout << "11\n";
        }
        cout << "0001111000\n";
        cout << "0010110110\n";
        cout << "0100011101\n";
        cout << eol;
    }
}

void decode() {
    int n, t;
    cin >> n >> t;
    while(t--) {
        int xr = rnd() % n + 1;
        vector<vector<int>> v(10, vector<int>(10));
        rep(i, 0, 10) rep(j, 0, 10) {
            char c;
            cin >> c;
            v[i][j] = c == '1';
        }

        int j8 = -1, j9 = -1;
        rep(j, 0, 10) {
            int sm = 0;
            rep(i, 0, 10) sm += v[i][j];
            if(sm == 8) {
                if(j8 == -1) j8 = j;
                else j9 = j;
            }
        }
        rep(i, 0, 10) swap(v[i][j9], v[i][9]), swap(v[i][j8], v[i][8]);
        rep(i, 0, 10) if(!v[i][8] && !v[i][9]) {
            swap(v[i], v[7]);
            break;
        }
        rep(i, 0, 10) if(i != 7 && (!v[i][8] || !v[i][9])) {
            int sm = 0;
            rep(j, 0, 10) sm += v[i][j];
            if(sm == 4) swap(v[i], v[8]);
            if(sm == 5) swap(v[i], v[9]);
        }
        
        array<int, 8> xd = {{0, 3, 2, 4, 1, 6, 7, 5}};
        rep(j, 0, 8) {
            int x = v[9][j] * 4 + v[8][j] * 2 + v[7][j];
            rep(i, 0, 10) swap(v[i][j], v[i][xd[x]]);
        }

        rep(i, 0, 7) {
            int x = v[i][5] * 4 + v[i][6] * 2 + v[i][7];
            swap(v[i], v[x]);
        }

        DEBUG {
            DC << "Normalised:";
            rep(i, 0, 10) {
                rep(j, 0, 10) DC << v[i][j];
                DC << eol;
            }
        }
        int ans = 0;
        rep(i, 0, 7) rep(j, 0, 5) ans = ans * 2 + v[i][j];
        ans ^= xr;
        cout << ans << eol;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    string s;
    cin >> s;
    rnd = mt19937(213769420);
    if(s[0] == 'A') encode();
    if(s[0] == 'B') decode();
}