import numpy as np

def Replacing():
    N = int(input())
    A = np.array(list(map(int,input().split())))
    Q = int(input())
    bc = [tuple(map(int,input().split())) for i in range(Q)]
    for i,j in bc:
        res = 0
        A = np.where(A == i, j, A)
        print(A.sum())
        
Replacing()
        