n = int(input())
a = list(map(int, input().split()))

A = {}
for i in range(n):
  if a[i] in A.keys():
    A[a[i]] += 1
  else:
    A[a[i]] = 1

ans = 0
for x in A.keys():
  ans += x * A[x]

q = int(input())
for i in range(q):
  b,c = list(map(int, input().split()))
  if b in A.keys():
    div = (A[b] * c) - (A[b] * b)
    ans += div
    if c in A.keys():
      A[c] += A[b]
      A[b] = 0
    else:
      A[c] = A[b]
      A[b] = 0  
    print(ans)

