from collections import Counter

def resolve():
  N = int(input())
  A = [int(x) for x in input().split(" ")]
  Q = int(input())

  countA = Counter(A)

  for _ in range(Q):
    B, C = map(int, input().split(" "))
    if B in countA.keys():
      countA[C] += countA.pop(B)
    sum_A = 0
    for a in countA.items():
      sum_A += a[0]*a[1]
    print(sum_A)

if __name__ == "__main__":
  resolve()
