import bisect
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
A.sort()
tmp_sum = sum(A)
for i in range(Q):
    b,c = map(int, input().split())
    left = bisect.bisect_left(A,b)
    if left < N:
        if A[left] == b:
            right = bisect.bisect_right(A,b)
            A[left:right] = [c] * (right-left)
            A.sort()
            tmp_sum = tmp_sum + c *(right-left) - b * (right - left)
            print(tmp_sum)
    else:
        print(tmp_sum)
