A = int(input())
B = list(map(int, input().split()))  
C = int(input())

sum_l=[]
for i in range(C):
  D = list(map(int, input().split()))
  
  for h in range(A):
    if B[h] == D[0]:
      B[h]=D[1]
    
  print(sum(B))

  