N = int(input())
a=list(map(int, input().split()))
Q = int(input())
num_a =[0]*100001
b=[]
c=[]
for i in range(Q):
  b1,c1=map(int, input().split())
  b.append(b1)
  c.append(c1)
for i in range(Q):
  if b[i] not in a:
    continue
  else:
    num_a[b[i]] = a.count(b[i])
num_b = []
for i in range(Q):
  if b[i] not in a:
    num_b.append(0)
  else:
    num_b.append(num_a[b[i]])
    num_a[c[i]] += num_a[b[i]]
    num_a[b[i]] = 0
sum = sum(a)
for i in range(Q):
  sum = sum - b[i]*num_b[i] +c[i]*num_b[i]
  print(sum)