n = int(input())
a_list = list(map(int, input().split()))
a_sum = sum(a_list)
q = int(input())

for i in range(q):
  b, c = map(int, input().split())
  if b not in set(a_list):
    print(a_sum)
    continue
  num = 0
  for j in range(len(a_list)):
    if a_list[j] == b:
      num += 1
      a_list[j] = c
  if b <= c:
    a_sum += (c - b) * num
  else:
    a_sum -= (b - c) * num
  print(a_sum)