N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B =[]
C =[]
BIGA= []
for i in range(Q):
	b,c = map(int,input().split())
	B.append(b)
	C.append(c)
for k in range(Q):
	for n, i in enumerate(A):
		if i == B[k]:
			A[n] = C[k]
	print(sum(A))

