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())))
BC=np.array(BC)

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