N = int(input())

A = [int(x) for x in input().split()]

Q = int(input())

for _ in range(Q):
  B,C = map(int,input().split())
  for i,v in enumerate(A):
    if v == B:
      A[i] = C
  
  print(sum(A))