n=int(input())
a = list(map(int, input().split()))
q=int(input())
b=[]
c=[]
for i in range(q):
  b1,c1=(int(x) for x in input().split())
  b.append(b1)
  c.append(c1)
for i2 in range(q):
  for j in range(len(a)):
    if a[j] == b[i2]:
      a[j] = c[i2]
  print(sum(a))