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