n = int(input())
arr = list(map(int, input().split()))
q = int(input())
for t in range(q):
	b, c = map(int, input().split())
	for x in range(len(arr)):
		if arr[x] == b:
			arr[x] = c
	sum = 0
	for y in range(len(arr)):
		sum = sum + arr[y]
	print(sum)