import numpy as np

n=input()
a=list(map(int, input().split()))
num = np.array(a)
q=int(input())

for i in range(q):
  s=list(map(int, input().split()))
  np.place(num, num==s[0], s[1])
  print(sum(num))