n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [list(map(int, input().split())) for i in range(q)]

count = 0
c = 0

for i in range(q):
    c = b[i][1]
    for j, item in enumerate(a):
        if item == b[i][0]:
            a.pop(j)
            count = count + 1
            
    print(sum(a) + c*count)