N = int(input())
A = list(map(int,input().split()))
Q = int(input())
for i in range(Q):
  b,c = map(int,input().split())
  if b in A:
    A = [c if i  == b else i for i in A]
    print(sum(A))
  else:
    print(sum(A))