import bisect

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0] * Q
C = [0] * Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())

A.sort()
Sum = sum(A)

for i in range(Q):
    L = bisect.bisect_left(A, B[i])
    R = bisect.bisect_right(A, B[i])
    num = R - L
    Sum += num * (C[i] - B[i])

    for j in range(L, R):
        A[j] = C[i]

    A.sort()
    print(Sum)
