import numpy as np
n = int(input())
A = list(map(int,input().split()))
q = int(input())
BC = [list(map(int,input().split())) for _ in range(q)]
A = np.array(A)
 
def main(A,BC):
    for bc in BC:
      A = np.where(A==bc[0],bc[1],A)
      print(sum(A))
        
if __name__ == '__main__':
    main(A,BC)