n = int(input())
num = list(map(int,input().strip().split()))
s = sum(num)
num_dict = {}
for i in num:
  if i in num_dict:
    num_dict[i] += 1
  else:
    num_dict[i] = 1
q = int(input())
for i in range(q):
  b,c = map(int,input().strip().split())
  if b in num_dict:
    num_dict[c] = num_dict[b]
    del num_dict[b]
    if b > c:
      s = s - (b-c)*num_dict[c]
      print(s)
    else:
      s = s + (c-b)*num_dict[c]
      print(s)
  else:
    print(s)
  