n = int(input())
als = list(map(int,input().split()))
ans = sorted(als)
q = int(input())
for i in range(q):
    b, c = map(int,input().split())
    if b in ans:
        cot = ans.count(b)
        ans =[ans[j] for j in range(n) if ans[j] != b]        
        for j in range(cot):
            ans.append(c)
    print(sum(ans))