from collections import Counter

N=int(input())
A=list(map(int,input().split()))
Q=int(input())
init=sum(A)
A=Counter(A)

for _ in range(Q):
    B,C=map(int,input().split())
    A[C]+=A[B]
    init=init-(B*A[B])+(C*A[B])
    print(init)
    A[B]=0