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

total = sum(a)
num = [0 for _ in range(10+1)]

for item in a:
  num[item] += 1
  
for i in range(q):
  total += (bc[i][1] - bc[i][0])*num[bc[i][0]]
  print(total)
  num[bc[i][1]] += num[bc[i][0]]
  num[bc[i][0]] = 0