import bisect

n = int(input())
an_list = list(map(int, input().split()))
an_list = sorted(an_list)

q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    index_r = bisect.bisect_right(an_list, b)
    index_l = bisect.bisect_left(an_list, b)
#     an_list[index_l:index_r] = [c for x in range(len(an_list[index_l:index_r]))]
    an_list[index_l:index_r] = [c] * (len(an_list[index_l:index_r]))
    print(sum(an_list))