def Replacing():
    N = int(input())
    A = 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
        for k in range(len(A)):
            if A[k] == i:
                A[k] = j
            res += A[k]
        print(res)
        
Replacing()
        