import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
Q=int(input())
somme=sum(A)
L=np.zeros(10**5+1)
for i in range(1,N+1):
    L[i]=sum(A==i)

for step in range(Q):
    b,c=map(int,input().split())
    somme=somme+(c-b)*L[b]
    L[c]=L[c]+L[b]
    print(int(somme))    