n=int(input())
a=list(map(int,input().split()))
sum_num=sum(a)
mylist=[0]*(10**5)
for i in range(1,10**5+1):
    mylist[i-1]=a.count(i)
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    sum_num+=(c-b)*mylist[b-1]
    print(sum_num)
    mylist[c-1]+=mylist[b-1]
    mylist[b-1]=0