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

using namespace std;

#define fi first
#define se second

typedef long long ll;

struct BigInt {
	vector<uint32_t> d;

	BigInt() {}

	BigInt(string s) {
		for(char c : s){
			mul_add(2, c - '0');
		}
	}

	void mul_add(uint32_t v, uint32_t a){
		uint64_t carry = a;
		for(int i = 0; i < (int)d.size(); i++){
			uint64_t cur = (uint64_t)d[i] * v + carry;
			d[i] = (uint32_t)(cur & 0xFFFFFFFF);
			carry = cur >> 32;
		}
		if(carry > 0){
			d.push_back((uint32_t)carry);
		}
	}

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

	string to_bin_string(int len){
		string s = "";
		BigInt temp = *this;
		for(int i = 0; i < len; i++){
			s += to_string(temp.div_mod(2));
		}
		reverse(s.begin(), s.end());
		return s;
	}
};

void solve(){
	string kto;
	if(!(cin >> kto)) exit(0);
	int n, t;
	cin >> n >> t;

	char znaki[] = {'P', 'K', 'N'};
	const int ROUNDS = 5500;

	while(t--){
		string s;
		cin >> s;

		BigInt moja_liczba(s);

		int moje_punkty = 0;
		int jego_punkty = 0;

		vector<int> jego_historia;
		vector<int> historia_roznicy;

		for(int runda = 0; runda < ROUNDS; runda++){
			int roznica = moje_punkty - jego_punkty;
			historia_roznicy.push_back(roznica);

			int moj_ruch = 0;

			if(roznica == 0) moj_ruch = moja_liczba.div_mod(3);
			else if(roznica == 1) moj_ruch = 1;
			else if(roznica == -1) moj_ruch = 0;

			cout << znaki[moj_ruch] << "\n";
			cout.flush();

			char jego_znak;
			cin >> jego_znak;

			int jego_ruch = 0;
			if(jego_znak == 'K') jego_ruch = 1;
			else if(jego_znak == 'N') jego_ruch = 2;

			jego_historia.push_back(jego_ruch);

			if((moj_ruch + 1) % 3 == jego_ruch){
				moje_punkty++;
			}
			else if((jego_ruch + 1) % 3 == moj_ruch){
				jego_punkty++;
			}
		}

		BigInt jego_liczba;

		for(int r = ROUNDS - 1; r >= 0; r--){
			int d_op = -historia_roznicy[r];
			int O = jego_historia[r];

			if(d_op == 0){
				jego_liczba.mul_add(3, O);
			}
		}

		string wynik = jego_liczba.to_bin_string(n);

		cout << "! " << wynik << "\n";
		cout.flush();
	}
}

bool multi = 0;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int t = 1;
	if(multi) cin >> t;

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

	return 0;
}