1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
i=[int(i)for i in input().split()];r=[[0] for _ in range(i[0])];f=""

def C(x,s):return

for _ in range(i[1]):
    o=input().split()
    if o[0]=='?':t=r[int(o[1])];f+=str((1 if t[0]==int(o[1])else 0)if len(t)==1 else'?')
    elif o[0]=='-':t=int(o[1]);r[t]=[0]
    else:
        a=int(o[1]);b=int(o[2])
        if r[a]==[a]:r[b]=[b]
        elif r[b]==[b]:r[a]=[a]
        if a==b:C(r[a],True);r[a]=[a]
        else:r[a].append(b);r[b].append(a);C(r[a],True)
print(f)