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 A[left] == b:
        right = bisect.bisect_right(A,b)
        A[left:right] = []
        n_left = bisect.bisect_left(A,c)
        A = A[:n_left] + [c] * (right - left) + A[n_left:]
        tmp_sum = tmp_sum + c *(right-left) - b * (right - left)
        print(tmp_sum)
    else:
        print(tmp_sum)