import math

n = int(input().strip())
a = [int(x) for x in input().strip().split(' ')]
q = int(input().strip())
bc = list()
for i in range(q):
    b,c = [int(x) for x in input().strip().split(' ')]
    bc.append((b,c))

a2 = list()
clear_list = a[:]
while clear_list:
    t = clear_list[0]
    a2.append([t,a.count(t)])
    clear_list = [x for x in clear_list if x != t]            

a2.sort()
for x in bc:
    for y in a2:
        print(x,y)
        if y[0] == x[0]:
            y[0] = x[1]
        elif y[0] > x[0]:
            break
    a2.sort()
    s = math.floor(sum([float(x[0]) * x[1] for x in a2]))
    print(s)
