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
#include <bits/stdc++.h>
// #define endl '\n'

using namespace std;
bool A = true;
int n, to[128];
constexpr char ch[3] = {'P', 'K', 'N'};
int grid[3][3] = {
   {0, 1, -1},
   {-1, 0, 1},
   {1, -1, 0}
};

auto prin = [](auto s) {
   if (A) cerr << s << '\n';
   cout << s << endl;
};

auto inp = [](auto &a) {
   cin >> a;
   if (A) cerr << a << '\n';
};

void solve() {
   string s; cin >> s;
   string out;
   for (char a : s) {
      char b = ch[a - '0'];
      prin(b);
      char c; inp(c);
      out.push_back((c == ch[0] ? '0' : '1'));
      if (!A) {
         prin(ch[1]); inp(c);
      } else {
         cerr << b << to[b] << ' ' << c << to[c] << '\n';
         int delta = grid[to[b]][to[c]];
         prin(ch[delta + 1]); inp(c);
      }
   }
   if (A) cerr << '\n';
   prin("! " + out);
}

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

   to['P'] = 0;
   to['K'] = 1;
   to['N'] = 2;

   string s; cin >> s;
   A = (s[0] == 'A');

   int t;
   cin >> n >> t;

   while (t--) {
      solve();
   }

   return 0;
}