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