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
#include <bits/stdc++.h>
using namespace std;
using ind = long long;
using cind = const ind;
#define FOR(i,l,r) for(ind i = (l); i <= (r); i++)
#define FORD(i,l,r) for(ind i = (l); i >= (r); i--)

ind max_N;
string person;
ind rands[501];

void solve(){
    char v[11][11];
    FOR(x,0,10) FOR(y,0,10) v[x][y]=0;
    if(person == "Algosia"){
        // cerr << "Algosia" << endl;
        ind N;
        cin >> N;
        // cerr << "Mam " << N << endl;
        bitset<120> b(0);
        FOR(i,1,60){
            b[i] = (N+rands[i])%2;
            N /= 2;
        }
        ind idx = 1;
        FOR(y,1,8) FOR(x,1,9-y){
            v[x][y] = b[idx];
            idx++;
        }
        FOR(k,1,10) v[k][11-k]=1;
        FOR(k,1,9){
            ind x = k;
            ind y = 10-x;
            v[x][y]=1;
        }
        FORD(y,10,1){
            string s;
            FOR(x,1,10) s.push_back('0'+v[x][y]);
            cout << s << endl;
            // cerr << "wypisane: " << s << endl;
        }
    }else{
        FORD(y,10,1){
            string s;
            cin >> s;
            FOR(x,1,10) v[x][y] = s[x-1]-'0';
        }
        ind current_bits_column[11];
        FOR(i,0,10) current_bits_column[i]=0;
        FOR(col,1,10){
            FOR(x,1,11-col){
                ind bits_added[11];
                FOR(y,1,10) bits_added[y] = current_bits_column[y] or v[x][y];
                ind sum=0;
                FOR(y,1,10) sum += bits_added[y];
                if(sum <= col){
                    FOR(i,1,10) current_bits_column[i] = bits_added[i];
                    FOR(y,1,10) swap(v[x][y],v[11-col][y]);
                    break;
                }
            }
        }
        ind current_bits_row[11];
        FOR(i,0,10) current_bits_row[i]=0;
        FOR(row,1,10){
            FOR(y,1,11-row){
                ind bits_added[11];
                FOR(x,1,10) bits_added[x] = current_bits_row[x] or v[x][y];
                ind sum=0;
                FOR(x,1,10) sum += bits_added[x];
                if(sum <= row){
                    FOR(i,1,10) current_bits_row[i] = bits_added[i];
                    FOR(x,1,10) swap(v[x][y],v[x][11-row]);
                    break;
                }
            }
        }
        FORD(y,10,1){
            string s;
            FOR(x,1,10) s.push_back('0'+v[x][y]);
            // cerr << "znalezione: " << s << endl;
        }
        bitset<120> b(0);
        ind idx = 1;
        FOR(y,1,8) FOR(x,1,9-y){
            b[idx] = v[x][y];
            idx++;
        }
        ind N=0;
        FORD(i,idx-1,1){
            N*=2;
            N+= (b[i] ^ rands[i]);
        }
        cout << N << endl;
    }
}
int main(){
    mt19937_64 rng_core(20260329);
    FOR(i,1,500) rands[i] = rng_core()%2;
    cin >> person;
    ind T;
    cin >> max_N >> T;
    FOR(i,1,T) solve();
}