N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
C=[]
for i in range(Q):
    b,c=input().split()
    B.append(int(b))
    C.append(int(c))
Set=set(A)
S=0
D={}
for s in Set:
    D[s]=A.count(s)
    S=S+s*D[s]
for i in range(Q):
    if B[i] in D:
        n=D[B[i]]
        S=S+n*(C[i]-B[i])
        del D[B[i]]
        if C[i] in D:
            D[C[i]]=n+D[C[i]]
        else:
            D[C[i]]=n
    print(S)