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
187
188
189
190
191
192
193
194
195
#include<bits/stdc++.h>
bool Mbg;
using namespace std;
#define vec vector
#define pb push_back
#define eb emplace_back
#define SZ(vec) (int)((vec).size())
#define all(vec) (vec).begin(),(vec).end()
#define pii pair<int,int>
#define x first
#define y second
#define mp make_pair
#define exc(expr) if(expr)continue;
#define stop(expr) if(expr)break;
#define ret(expr) if(expr)return;
#define deb(var) std::cerr<<#var<<'='<<(var)<<"; "
#define debl(var) std::cerr<<#var<<'='<<(var)<<";\n"
#define debs(...) std::cerr << "(" << #__VA_ARGS__ << ")=(", deb_out(__VA_ARGS__)
void deb_out() { cerr<<");\n"; }
template <typename H>void deb_out(H h) { std::cerr << h << ");\n"; }
template <typename H, typename...T>void deb_out(H h, T... t){ std::cerr << h << ","; deb_out(t...); }
template<typename T>std::ostream& operator <<(std::ostream& os,const vector<T>& arr){
    if(arr.empty())return os;
    os<<arr[0];
    for(int i=1;i<arr.size();i++)os<<' '<<arr[i];
    return os;
}
#define ins insert
#define era erase
#define lb lower_bound
#define ub upper_bound
#define int long long
#define inf (long long)(1.1e18)
template<typename T>bool Min(T &x,const T &y){return x>y?x=y,1:0;}
template<typename T>bool Max(T &x,const T &y){return x<y?x=y,1:0;}
const int mod=998244353;
void Add(int &x,const int &y){x=x+y<mod?x+y:x+y-mod;}
void Dec(int &x,const int &y){x=x>=y?x-y:x-y+mod;}
int fpm(int x,int y){
    int ans=1;for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)ans=1ll*x*ans%mod;return ans;
}
string role;
int n,T;
int f1(unsigned long long x){
    // return 0;
    return __builtin_parityll(17*x*x*x+19*x*x+114547);
}
int f2(unsigned long long x){
    // return 0;
    return __builtin_parityll(x*114+3*x*x+19*x*x*x+1919810);
}

/*
PKN:布、石头、剪刀
012

0<1<2<0
*/
void play(){
    string s;
    cin>>s;
    if(role=="Algosia"){
        for(int i=0;i<n;i++)s[i]^=f1(i);
    }else{
        for(int i=0;i<n;i++)s[i]^=f2(i);
    }
    s.pb('0');
    s.pb('0');
    s.pb('0');
    s.pb('0');

    int a=0,b=0;
    int score=0;
    // my-other

    string t(n+5,'?');
    while(a<n||b<n){
        int P=-1,Q=-1;
        auto play=[&](int x){
            cout<<"PKN"[x]<<endl;
            P=x;
        };
        int a2=a;
        if(score==0){
            if(s[a]=='0'&&s[a+1]=='0'){
                play(0);
                a2+=2;
            }else if(s[a]=='0'&&s[a+1]=='1'){
                play(1);
                a2+=2;
            }else{
                play(2);
                ++a2;
            }
        }else if(score==1){
            if(a<b||a==b&&role=="Algosia"){
                if(s[a]=='0'){
                    play(0);
                }else{
                    play(2);
                }
                ++a2;
            }else{
                play(0);
            }
        }else{
            if(a<b||a==b&&role=="Algosia"){
                if(s[a]=='0'){
                    play(0);
                }else{
                    play(1);
                }
                ++a2;
            }else{
                play(0);
            }
        }

        
        string ch;
        cin>>ch;
        Q=ch=="P"?0:ch=="K"?1:2;

        if(score==0){
            if(Q==0){
                t[b++]='0';
                t[b++]='0';
            }else if(Q==1){
                t[b++]='0';
                t[b++]='1';
            }else if(Q==2){
                t[b++]='1';
            }
        }else if(score==1){
            if(a<b||a==b&&role=="Algosia"){
            }else{
                if(Q==0){
                    t[b++]='0';
                }else if(Q==1){
                    t[b++]='1';
                }else{
                    assert(0);
                }
            }
        }else{
            if(a<b||a==b&&role=="Algosia"){
            }else{
                if(Q==0){
                    t[b++]='0';
                }else if(Q==2){
                    t[b++]='1';
                }else{
                    assert(0);
                }
            }
        }
        a=a2;

        if(P!=Q){
            if(P==(Q+1)%3)++score;
            else --score;
        }
        assert(abs(score)<=1);
        a=min(a,n);
        b=min(b,n);
    }
    while(SZ(t)>n)t.pop_back();
    if(role=="Algosia"){
        for(int i=0;i<n;i++)t[i]^=f2(i);
    }else{
        for(int i=0;i<n;i++)t[i]^=f1(i);
    }
    for(auto x:t)assert(x=='0'||x=='1');
    cout<<"! "<<t<<endl;
}
void work(){
    cin>>role;
    cin>>n>>T;
    while(T--){
        play();
    }
}
bool Med;
signed main(){
    // ios::sync_with_stdio(0),
    // cin.tie(0),cout.tie(0);
    int T=1;while(T--)work();
    // cerr<<"Time: "<<clock()<<" ms;\n";
    // cerr<<"Memory: "<<abs(&Med-&Mbg)/1024.0/1024.0<<" MiB.\n";
}
/*
- CONTINUE, NON-STOPPING, FOR THE FAITH
- START TYPING IF YOU DON'T KNOW WHAT TO DO
- STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
*/