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())
P = [list(map(int,stdin.readline().split())) for i in range(Q)]
for i in range(0,Q):
    if E.count(P[i][0])>0:
        j=E.index(P[i][0])
        if E.count(P[i][1])>0:
            k=E.index(P[i][1])
            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]=P[i][1]*F[j]
            E[j]=P[i][1]
    print(sum(G))