N = int(input())
A = list(map(int, input.split()))
Q = int(input())
B = []
C = []
for q = in range(Q):
	b, c = map(int, input.split())
	B.append(b)
	C.append(c)

sm = sum(A)

for q in range(Q):
	ctb = A.count(B[q])
	sm += (C[q]-B[q])*ctb
	print(sm)
	