import bisect

n = int(input())
an_list = list(map(int, input().split()))
an_list = sorted(an_list)
max_num = max(an_list)
min_num = min(an_list)

q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    if min_num <= b and b <= max_num:
        index_l = bisect.bisect_left(an_list, b)
#         print(an_list[index_l] == b)
        if an_list[index_l] == b:
            index_r = bisect.bisect_right(an_list, b)
            an_list[index_l:index_r] = [c] * (len(an_list[index_l:index_r]))
            an_list = sorted(an_list)
            max_num = max(an_list)
            min_num = min(an_list)
    print(sum(an_list))
#     print(an_list)