N = int(input())
a = list(map(int,input().split()))
q = int(input())
num = []
summ = 0
for i in range(10**5):
  num.append(0)
for i in range(N):
  num[a[i]-1] += 1
  summ += a[i]
for i in range(q):
  b,c = map(int,input().split())
  summ += (c-b)*a[b-1]
  a[c-1] += a[b-1]
  a[b-1] = 0
  print(summ)
