n=int(input())
a=list(map(int,input().split()))
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]

for j in range(q):
  for i in range(n):
    if a[i]==bc[j][0]:
      a[i]=bc[j][1]
  print(sum(a))