N = int(input())
A = list(map(int, input().split()))
Q = int(input())
P = [(0,0)] * Q
for i in range(Q):
	b, c = list(map(int, input().split()))
	P[i] = (b, c)

for i in range(Q):
	for j in range(N):
		if A[j] == P[i][0]:
			A[j] = P[i][1]

	print(sum(A))