n = int(input())
a = list(map(int,input().split()))
q = int(input())
res = []
a_sum = sum(a)

for i in range(q):
    b,c = list(map(int,input().split()))
    co = a.count(b)
    for j in range(co):
        a[a.index(b)] = c
        a_sum += (c - b)
    
    res.append(a_sum)
        
for i in res:
    
    print(i)