#入力
N = int(input())
Alist = list(map(int,input().split()))
Q = int(input())
Blist = []
Clist = []
for i in range(Q):
  B, C = map(int,input().split())
  Blist.append(B)
  Clist.append(C)

for j in range(Q):
  for k in range(len(Alist)):
    if Alist[k] == Blist[j]:
      Alist[k] = Clist[j]
  print(sum(Alist))