N = int(input())
A = list(map(int, input().split()))
lis = {}
Q = int(input())
for x in A:
  if x in lis:
    lis[x] += 1
  else:
    lis[x] = 1
for i in range(Q):
  B, C = map(int, input().split())
  try:
    temp = lis[B]
    del lis[B]
    if lis == {} or not C in lis:
      lis[C] = temp
    else:
      lis[C] += temp
  except:
    pass
  ans = 0
  for x in lis:
    ans += x * lis[x]
  print(ans)