from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
q = int(input())

for _ in range(q):
  b,c = map(int, input().split())
  if b in a:
    ans = 0
    t = a.pop(b)
    if c in a:
      a[c] += t
    else:
      a[c] = t
    for x,y in a.items():
      ans += x*y
    print(ans)
  else:
    print(ans)