1length=int(raw_input())
2s=set(map(int, raw_input().split()))
3N=int(raw_input())
4
5for i in range(N):
6 (p, q)=raw_input().split()
7 s2=set(map(int, raw_input().split()))
8 if p=='intersection_update':
9 s.intersection_update(s2)
10 elif p=='update':
11 s.update(s2)
12 elif p=='symmetric_difference_update':
13 s.symmetric_difference_update(s2)
14 elif p=='difference_update':
15 s.difference_update(s2)
16print sum(s)