import collections
N=int(input())
A=list(map(int, input().split()))
Q=int(input())
B=[0]*Q
C=[0]*Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())
    
A_dict=collections.Counter(A)
for i in range(Q):
    ANS=0
    if B[i] in A_dict.keys():
        if C[i] in A_dict.keys():
            A_dict[C[i]]+=A_dict[B[i]]
            del A_dict[B[i]]
        else:
            A_dict[C[i]] = A_dict[B[i]]
            del A_dict[B[i]]
    for j in A_dict.keys():
        ANS=ANS+j*A_dict[j]
    print(ANS)