mod = int(1e9+7)
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    #A, B = [int(x) for x in raw_input().split()]
    n = int(raw_input())
    
    arr = [int(x) for x in raw_input().split()]
    
    cnt = {}
    
    cur_sum = 0
    
    for num in arr:
        cnt[num] = cnt.get(num, 0) + 1
        cur_sum += num 
    
    q = int(raw_input())
    
    for _ in range(q):
        frm, to = [int(x) for x in raw_input().split()]
        
        frm_cnt, to_cnt = cnt.get(frm, 0), cnt.get(to, 0)
        
        diff = to - frm
        
        total_diff = frm_cnt * diff
        
        cur_sum += total_diff
        
        cnt[to] = to_cnt + frm_cnt
        
        cnt[frm] = 0
        
        print(cur_sum)
        
        
           
        
    
    #queries = [ for x in raw_input().split()]
    

main()