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

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