N = int(input())
A = map(int, input().split())
Q = int(input())



A = list(A)
for _ in range(Q):
	# replace every element whose value is B with C
	B, C = map(int, input().split())

	for i in range(len(A)):
		if A[i] == B:
			A[i] = C
	print(sum(A))