N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]
# print(N)
# print(A)
# print(Q)
# print(B)

for i in range(Q):
    Bi = BC[i][0]
    Ci = BC[i][1]

    for j in range(len(A)):
        if A[j] == Bi:
            A[j] = Ci
    
    print(sum(A))
