# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
Adic={}
B=0

for i in A:
    Adic[i]=0

for i in A:
    Adic[i]+=1

for i in range(Q):
    b,c=map(int,input().split())
    
    if b not in Adic:
        for k,v in Adic.items():
            B+=k*v
        print(B)
        B=0
    else:
        
        if c in Adic:
            Adic[c]+=Adic[b]
            Adic[b]=0
        elif c not in Adic:
            Adic[c]=0
            Adic[c]+=Adic[b]
            Adic[b]=0
            
        for k,v in Adic.items():
            B+=k*v
        print(B)
        B=0