import numpy as np
def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0 for _ in range(Q)]
C = [0 for _ in range(Q)]
for i in range(Q):
  B[i], C[i] = map(int, input().split())
  
for i in range(Q):
  index = my_index(A, B[i])
  while(index != -1):
    A[index] = C[i]
    index = my_index(A, B[i])

  print(np.sum(A))