n = int(input())
a = set(map(int, input().split()))
q = int(input())
ll = []
for i in range(q):
	l = list(map(int, input().split()))
	ll.append(l)
    
for i in ll:
  if i[0] in a:
    a = [i[1] if j == i[0] else j for j in a]
    print(sum(a))
  else:
    print(sum(a))