import numpy as np

ans = 0

N=int(input())
A=list(map(int,input().split()))
npA=np.array(A)

uniqA, counts = np.unique(npA, return_counts=True)
ans = np.sum(npA)

Q=int(input())

for q in range(Q):
	diff = 0
	B,C = map(int,input().split())

	if B in uniqA:
		srcIndex = np.where(uniqA == B)[0]
		srcCount = int(counts[srcIndex])
		diff = ( C - int(uniqA[srcIndex]) ) * srcCount
		counts[srcIndex] = 0
		if C in uniqA:
			counts[np.where(uniqA == C)[0]] += srcCount
		else:
			uniqA = np.append(uniqA, C)
			counts = np.append(counts, srcCount)

	ans += diff
	print(ans)

