N,M = map(int, input().split()) G = {} Cls = set() for _ in range(M): u,v = map(int, input().split()) if u not in G: G[u] = set() G[u].add(v) Q = int(input()) for _ in range(Q): q,a,b = map(int, input().split()) if a not in G: G[a] = set() if q == 1: if b in G[a]: G[a].remove(b) else: G[a].add(b) else: if a in Cls: Cls.remove(a) else: Cls.add(a) num = N-len(Cls-G[a]) if a in Cls: print(num) else: print(num-1)