n = int(input())
l = [int(x) for x in input().split()]
m = {x : 0 for x in l}

for x in l:
  m[x] += 1

for i in range(int(input())):
  b, c = map(int, input().split())
  if b not in m:
    print(sum([k * v for k, v in m.items()]))
    continue
  
  cnt = m[b]
  m[b] = 0
  m[c] = m[c] + cnt if c in m else cnt
  
  print(sum([k * v for k, v in m.items()]))