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

#define all(v) (v).begin(), (v).end()
#define st first
#define nd second
#define pb push_back
#define printv(a) { for(auto u : a) cout<<u<<" "; cout<<"\n"; }
#define debug(x) cerr << #x << " = " << x << '\n';

using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using si = set<int>;
using mii = map<int,int>;

int przew = 0;

void ruch(char c){
    cout<<c<<endl;
}

int wynik(char c1,char c2){
    if(c1 == 'P' && c2 == 'K') return 1;
    if(c1 == 'K' && c2 == 'N') return 1;
    if(c1 == 'N' && c2 == 'P') return 1;
    if(c2 == 'P' && c1 == 'K') return -1;
    if(c2 == 'K' && c1 == 'N') return -1;
    if(c2 == 'N' && c1 == 'P') return -1;
    return 0;
}

void solve(int n){
    string s, wyn;
    cin>>s;
    przew = 0;
    int i = 0;
    while(i < n){
        //cout<<" jestesmy w "<<i<<" przewaga to "<<przew<<endl;
        char c1,c2;
        if(przew == 0){
            if(s[i] == '0'){
                c1 = 'P';
            }else{
                c1 = 'K';
            }
            ruch(c1);
            i++;
            cin>>c2;
            if(c2 == 'P') wyn += '0';
            else wyn += '1';
            przew += wynik(c1,c2);
            continue;
        }
        if(przew == 1) c1 = 'P';
        if(przew == -1) c1 = 'N';
        ruch(c1);
        cin>>c2;
        przew += wynik(c1,c2);
    }
    cout<<"! "<<wyn<<endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string t;
    cin>>t;
    int n,q;
    cin>>n>>q;
    while(q--){
        solve(n);
    }
    return 0;
}