N=int(input())
A=list(map(int,input().split()))
Q=int(input())
bc=[map(int, input().split()) for _ in range(Q)]
b,c=[list(i) for i in zip(*bc)]

for i in range(Q):
  A=[c[i] if x==b[i] else x for x in A]
  print(sum(A))