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
n, q = map(int, input("").split())
m = {}
M = {}
wynik = []
for i in range(n):
    m[i + 1] = 0
    M[i + 1] = "0"
for i in range(q):
    x = input("").split()
    if list(M.values()).count("?") == 1:
        for klucz, wartosc in M.items():
            if wartosc == "?":
                M[klucz] = 1
                break
    if x[0] == "+":
        if x[1] == x[2]:
            M[int(x[1])] = 1
        elif M[int(x[1])] == "?" and M[int(x[2])] == "?":
            M[int(x[1])] = 1
            M[int(x[2])] = 1
        else:
            M[int(x[1])] = "?"
            M[int(x[2])] = "?"
    elif x[0] == "-":
        M[int(x[1])] = 0
    elif x[0] == "?":
        wynik.append(str(M[int(x[1])]))
print("".join(wynik))