import collections

def A_sum(A):
  s = 0
  for i in A.items():
    s+=i[0]*i[1]
  print(s)

def A_rep(A,f,t):
  f_num = A.get(f)
  if f_num != None:
      A[t]=A.get(t,0) + f_num
      A.pop(f)

N = int(input())
A = collections.Counter(map(int,input().split()))
Q = int(input())
for i in range(Q):
  b,c = map(int,input().split())
  A_rep(A,b,c)
  A_sum(A)
