
n=int(input())
a=list(map(int,input().split()))
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
num=[a.count(i+1) for i in range(10**5)]
sum=sum(a)
for i in range(q):
    x=bc[i][0]
    y=bc[i][1]
    sum+=(y-x)*num[x-1]
    num[y-1]+=num[x-1]
    num[x-1]=0
    print(sum)