n = int(input())
a = input().split()
def check(a,num,b):
  sum = 0
  for i in range(num):
    if a[i] == b[0]:
      sum += int(b[1])
      a[i] = b[1]
    else:
      sum += int(a[i])
  return a,sum
q = int(input())
for i in range(q):
  b = input().split()
  a,sum = check(a,n,b)
  print(sum)