N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B,C,S = [0 for i in range(Q)],[0 for i in range(Q)],[0 for i in range(Q)]
for i in range(Q):
    B[i],C[i] = map(int,input().split())


for j in range(Q):
    b,c = B[j],C[j]
    for i in range(N):
        if A[i]==b:
            A[i] = c
        S[j] = S[j]+A[i]
    print(S[j])
