from collections import Counter
n=int(input())
a=list(map(int,input().split()))
q=int(input())
ans=sum(a)
list1=(Counter(a))
b=[0]*q
c=[0]*q
ct=0
for i in range(q):
    b[i],c[i]=list(map(int,input().split()))
for i in range(q):
    if list1[b[i]]>0 :
        if list1[c[i]]==0:
            list1[c[i]]=0
            list1[c[i]]+=list1[b[i]]
            ans=ans-(b[i]*list1[b[i]])+(c[i]*(list1[c[i]]))        
            list1[b[i]]=0
        else:
            ans=ans-(b[i]*list1[b[i]])+(c[i]*(list1[c[i]]))
            list1[c[i]]+=list1[b[i]]  
            list1[b[i]]=0  
    print(ans)