N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = []

def my_index(l, x, default=False):
    if x in l:
        return l.index(x) + 1
    else:
        return default

for i in range(Q):
  BC.append(list(map(int, input().split())))

for i in range(Q):
  ind = my_index(A, BC[i][0])
  while ind:
    A[ind - 1] = BC[i][1]
    ind = my_index(A, BC[i][0])
  
  print(sum(A))