n=int(input())
arr=list(map(int,input().strip().split()))
k=int(input())
d=dict()
for i in range(n):
    d[arr[i]]=0
for i in range(n):
    d[arr[i]]=d[arr[i]]+1
sumi=0
for i in range(n):
    sumi=sumi+arr[i]
for i in range(k):
    a,b=[int(a) for a in input().split()]
    e1=d[a]*a
    e2=d[b]*b
    sumi=sumi+e2-e1
    print(sumi)
    d[b]=d[b]+d[a]
    d[a]=0
    
    

    