#input
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
array = [list(map(int, input().split())) for _ in range(Q)]
#variable
count = []
number = []
S = []
n = 0

A.sort()
while True:
    number.append(A[n])
    count.append(A.count(number[len(number)-1]))
    n = n + count[len(count)-1]
    print(n)
    if n >= N or count[0] == N:
        break


print(number)
print(count)
while len(S)  < Q :
    n = 0
    for i in range(len(number)):
        if number[i] == array[len(S)][0]:
            number[i] = array[len(S)][1]
        n = n + number[i] * count[i]
    S.append(n)
for i in S[0:]:
    print(i)