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
import sys

def flush_print(s):
    sys.stdout.write(s + "\n")
    sys.stdout.flush()

who = sys.stdin.readline().strip()  # "Algosia" lub "Bajtek"
line = sys.stdin.readline().split()
n = int(line[0]); t = int(line[1])

for _ in range(t):
    me = sys.stdin.readline().strip()  
    # rejestracja odpowiedzi usera runda po runde
    opponent_bits = []
    # bedziemy przeprowadzać 2 rundy na bit
    for i in range(n):
        mybit = me[i]
        # pierwsza runda dla tej pozycji
        if mybit == '0':
            send1 = 'P'
            send2 = 'K'
        else:
            send1 = 'K'
            send2 = 'P'

        # runda 1
        flush_print(send1)
        opp1 = sys.stdin.readline().strip()
        # runda 2
        flush_print(send2)
        opp2 = sys.stdin.readline().strip()

        # dekoduj bit przeciwnika
        if opp1 == 'P' and opp2 == 'K':
            ob = '0'
        elif opp1 == 'K' and opp2 == 'P':
            ob = '1'
        else:
            # nieoczekiwane — daj 0
            ob = '0'
        opponent_bits.append(ob)

    decoded = "".join(opponent_bits)
    flush_print("! " + decoded)