from sys import stdin
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
D=Counter(A)
E=list(D.keys())
F=list(D.values())
G=[0]*len(E)
for i in range(0,len(D)):
    G[i]=E[i]*F[i]
Q=int(input())
Z=[0]*Q
for i in range(0,Q):
    B,C=list(map(int,input().split()))
    if E.count(B)>0:
        j=E.index(B)
        if E.count(C)>0:
            k=E.index(C)
            G[k]=G[k]+E[k]*F[j]
            F[k]=F[k]+F[j]
            E.pop(j)
            F.pop(j)
            G.pop(j)
        else:
            G[j]=C*F[j]
            E[j]=C
    Z[i]=sum(G)
for i in range(0,Q):
    print(Z[i])