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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

struct BigInt {
    vector<uint32_t> d;
    
    BigInt() {}
    
    void add_small(uint32_t v) {
        uint32_t carry = v;
        for (size_t i = 0; i < d.size() || carry; ++i) {
            if (i == d.size()) d.push_back(0);
            uint64_t cur = (uint64_t)d[i] + carry;
            d[i] = cur;
            carry = cur >> 32;
        }
        while (d.size() && d.back() == 0) d.pop_back();
    }

    void mul_small(uint32_t v) {
        if (v == 1) return;
        if (v == 0) { d.clear(); return; }
        uint32_t carry = 0;
        for (size_t i = 0; i < d.size() || carry; ++i) {
            if (i == d.size()) d.push_back(0);
            uint64_t cur = (uint64_t)d[i] * v + carry;
            d[i] = cur;
            carry = cur >> 32;
        }
        while (d.size() && d.back() == 0) d.pop_back();
    }

    void add_mul(const BigInt& a, uint32_t m) {
        if (m == 0) return;
        uint32_t carry = 0;
        for (size_t i = 0; i < a.d.size() || carry; ++i) {
            if (i == d.size()) d.push_back(0);
            uint64_t cur = (uint64_t)d[i] + (i < a.d.size() ? (uint64_t)a.d[i] * m : 0) + carry;
            d[i] = cur;
            carry = cur >> 32;
        }
        while (d.size() && d.back() == 0) d.pop_back();
    }

    uint32_t div_mod(uint32_t base) {
        if (base == 1) return 0;
        uint32_t rem = 0;
        for (int i = (int)d.size() - 1; i >= 0; i--) {
            uint64_t cur = ((uint64_t)rem << 32) + d[i];
            d[i] = cur / base;
            rem = cur % base;
        }
        while (d.size() && d.back() == 0) d.pop_back();
        return rem;
    }

    int bit_len() const {
        if (d.empty()) return 0;
        int bits = (d.size() - 1) * 32;
        uint32_t last = d.back();
        while (last) { bits++; last >>= 1; }
        return bits;
    }

    string to_bin(int N) {
        string s = "";
        BigInt temp = *this;
        for (int i = 0; i < N; ++i) {
            uint32_t rem = temp.div_mod(2);
            s += (char)('0' + rem);
        }
        reverse(s.begin(), s.end());
        return s;
    }
};

BigInt from_bin(const string& s) {
    BigInt res;
    for (int i = 0; i < (int)s.length(); ++i) {
        res.mul_small(2);
        if (s[i] == '1') res.add_small(1);
    }
    return res;
}

char to_char(int move) {
    if (move == 0) return 'K';
    if (move == 1) return 'P';
    return 'N';
}

int from_char(char c) {
    if (c == 'K') return 0;
    if (c == 'P') return 1;
    return 2;
}

int get_score(int moveA, int moveB) {
    if (moveA == moveB) return 0;
    if ((moveA + 2) % 3 == moveB) return 1;
    return -1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string role_str;
    if (!(cin >> role_str)) return 0;
    bool is_algosia = (role_str == "Algosia");

    int n, t;
    cin >> n >> t;

    while (t--) {
        string my_str;
        cin >> my_str;
        BigInt Val = from_bin(my_str);

        BigInt MulA; MulA.add_small(1);
        BigInt MulB; MulB.add_small(1);
        BigInt RecA, RecB;
        
        int S = 0; 

        while (MulA.bit_len() <= n || MulB.bit_len() <= n) {
            int baseA = (S == 0) ? 3 : (S == 1 ? 2 : 1);
            int baseB = (S == 0) ? 3 : (S == 1 ? 1 : 2);

            int remA = 0, remB = 0;
            int moveA = 0, moveB = 0;

            if (is_algosia) {
                remA = Val.div_mod(baseA);
                if (baseA == 3) moveA = remA;
                else if (baseA == 2) moveA = (remA == 0 ? 0 : 2);
                else moveA = 0;

                cout << to_char(moveA) << "\n";
                cout.flush();

                char opp; cin >> opp;
                moveB = from_char(opp);

                if (baseB == 3) remB = moveB;
                else if (baseB == 2) remB = (moveB == 0 ? 0 : 1);
                else remB = 0;

                RecB.add_mul(MulB, remB);
                MulA.mul_small(baseA);
                MulB.mul_small(baseB);
            } else {
                remB = Val.div_mod(baseB);
                if (baseB == 3) moveB = remB;
                else if (baseB == 2) moveB = (remB == 0 ? 0 : 2);
                else moveB = 0;

                cout << to_char(moveB) << "\n";
                cout.flush();

                char opp; cin >> opp;
                moveA = from_char(opp);

                if (baseA == 3) remA = moveA;
                else if (baseA == 2) remA = (moveA == 0 ? 0 : 1);
                else remA = 0;

                RecA.add_mul(MulA, remA);
                MulA.mul_small(baseA);
                MulB.mul_small(baseB);
            }

            S += get_score(moveA, moveB);
        }

        string ans = is_algosia ? RecB.to_bin(n) : RecA.to_bin(n);
        cout << "! " << ans << "\n";
        cout.flush();
    }

    return 0;
}