import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
BC=[]
for i in range(Q):
    BC.append(list(map(int, input().split())))


print()
for i in range(Q):
    look_0=BC[i][0]
    look_1=BC[i][1]
    if look_0 not in A:
        pass
    else:
        sub_array=(A==look_0)
        not_sub_array=np.logical_not(sub_array)
        sub_array=sub_array*look_1
        A=A*not_sub_array
        A=A+sub_array
    sum_A=np.sum(A)
    print(sum_A)
