n=int(input())
a=list(map(int,input().split()))

adic=dict()

for ai in a:
    if ai in adic:
        adic[ai]+=1
    else:
        adic[ai]=1
        
q=int(input())
b=[0]*(q+1)
c=[0]*(q+1)
for i in range(q):
    b[i],c[i]=map(int,input().split())
    
#print(adic)    
for i in range(q):
    if b[i] in adic and c[i] in adic:
        adic[c[i]]=adic[c[i]]+adic[b[i]]
        del adic[b[i]]
    elif b[i] in adic and (not c[i] in adic):
        adic[c[i]]=adic[b[i]]
        del adic[b[i]]
#        adic[b[i]]=0
#    print(i,adic)
    asum=0
    for i,ad in adic.items():
        asum+=i*ad
    print(asum)
    