import numpy as np

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

ans = []
b= []
for c1 in range (q):
    b.append( list(map(int, input().split())) )
    c2=a.count(b[c1][0])

    if (c2!=0):
        for c3 in range(c2):
            a.remove(b[c1][0])
            a.append(b[c1][1])
        
    ans.append(np.sum(a) )
    print(ans[c1])
    
    
