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

#define ll long long
#define pi std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi std::vector<int>
#define vll std::vector<ll>
#define vpi std::vector<pi>
#define vpll std::vector<pll>
#define si std::set<int>

void natroj(vi &v, vi &dist)
{
    vi help = v;

    while (!help.empty())
    {
        vi next;

        int reszta = 0;

        for (int i = 0; i < help.size(); i++)
        {
            int c = reszta * 2 + help[i];
            reszta = c % 3;

            if (!next.empty() || c / 3 != 0)
                next.push_back(c / 3);
        }

        dist.push_back(reszta);
        help = next;
    }

    std::reverse(dist.begin(), dist.end());
}

void nabit(vi &troj, vi &bin, int n)
{

    vi help = troj;

    while (!help.empty())
    {
        vi next;

        int reszta = 0;

        for (int i = 0; i < help.size(); i++)
        {
            int c = reszta * 3 + help[i];
            reszta = c % 2;

            if (!next.empty() || c / 2 != 0)
                next.push_back(c / 2);
        }

        bin.push_back(reszta);
        help = next;
    }

    if (bin.empty())
        bin.push_back(0);

    std::reverse(bin.begin(), bin.end());
    if (bin.size() < n)
    {
        vi help(n - bin.size(), 0);
        help.insert(help.end(), bin.begin(), bin.end());
        bin = help;
    }
}

void solve(std::string nazwa, int n, int t)
{
    std::string ciag;

    std::cin >> ciag;
    std::vector<int> v(n), ans, czyt;

    for (int i = 0; i < n; i++)
        v[i] = ciag[i] - '0';

    int id = 0;
    if (nazwa == "Bajtek")
        id = 1;

    std::vector<int> maska0(n), maska1(n);

    std::mt19937 rng(12345); // Stały seed
    std::uniform_int_distribution<int> dist(0, 1);

    for (int i = 0; i < n; i++)
    {
        maska0[i] = dist(rng);
        maska1[i] = dist(rng);
    }

    if (id == 0)
    {
        for (int i = 0; i < n; i++)
            if (maska0[i])
                v[i] = !v[i];
    }
    else
        for (int i = 0; i < n; i++)
            if (maska1[i])
                v[i] = !v[i];

    std::vector<int> troj;
    natroj(v, troj);

    for (int i = 0; i < 5498; i++)
    {
        char gram;
        if (!troj.empty())
        {
            if (troj.back() == 0)
                gram = 'P';
            else if (troj.back() == 1)
                gram = 'K';
            else
                gram = 'N';
            troj.pop_back();
        }
        else
            gram = 'P';

        std::cout << gram << std::endl;
        std::cout.flush();

        char gra;
        std::cin >> gra;

        if (gram != gra) {
            if ((gram == 'P' && gra == 'K') || (gram == 'K' && gra == 'N') || (gram == 'N' && gra == 'P'))
                std::cout << 'P' << std::endl;
            else
                std::cout << 'N' << std::endl;
            i++;
        }
        std::cout.flush();

        if (gra == 'P')
            czyt.push_back(0);
        else if (gra == 'K')
            czyt.push_back(1);
        else
            czyt.push_back(2);

        if(gram != gra)
            std::cin >> gra;
    }

    std::reverse(czyt.begin(), czyt.end());

    nabit(czyt, ans, n);

    if (id == 0)
    {
        for (int i = 0; i < n; i++)
            if (maska1[i])
                ans[i] = !ans[i];
    }
    else
        for (int i = 0; i < n; i++)
            if (maska0[i])
                ans[i] = !ans[i];

    std::cout << "! ";
    for (int i = 0; i < n; i++)
        std::cout << ans[i];
    std::cout << std::endl;
    std::cout.flush();
}

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

    std::string nazwa;
    int n, t;
    std::cin >> nazwa >> n >> t;
    for (int i = 0; i < t; i++)
        solve(nazwa, n, t);
}