import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
BC = [tuple(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    temp = A == BC[i][0]
    temp = temp.astype(np.int)
    temp = temp * BC[i][1]

    temp2 = A != BC[i][0]
    temp2 = temp2.astype(np.int)

    A = A*temp2 + temp

    print(A.sum())
