import sys
input = sys.stdin.readline

s = set()
tmp = set(range(1, 21))
m = int(input())

for _ in range(m):
    cmd = input().strip().split()
    
    # add이고 x가 집합에 없는 경우
    if cmd[0] == 'add' and int(cmd[-1]) not in s:
        s.add(int(cmd[-1]))

    # remove이고 x가 집합에 있는 경우
    elif cmd[0] == 'remove' and int(cmd[-1]) in s:
        s.discard(int(cmd[-1]))

    # check
    elif cmd[0] == 'check':
        if int(cmd[-1]) in s:
            print(1)
        else:
            print(0)
    
    # toggle
    elif cmd[0] == 'toggle':
        if int(cmd[-1]) in s:
            s.discard(int(cmd[-1]))
        else:
            s.add(int(cmd[-1]))

    # all
    elif cmd[0] == 'all':
        s = tmp.copy()
    
    # empty
    else:
        s = set()