import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
B = [0]*Q
C = [0]*Q

sum = np.sum(A)

for i in range(Q):
    B[i], C[i] = map(int, input().split())
    
    time = 0
    A = np.sort(A)
    for k in range(N):
        if A[k] == B[i]:
            A[k] = C[i]
            time += 1
        elif A[k] > B[i]:
            break
        
    sum += (C[i]-B[i])*time

    print(sum)