n = int(input())
ls = list(map(int,input().split()))
q = int(input())
qls = []
for i in range(q):
	a, b = input().split()
	a, b = int(a), int(b)
	subls = []
	subls.append(a)
	subls.append(b)
	qls.append(subls)

total = sum(ls)
setls = list(set(ls))

freqlist = dict()

for i in setls:
	freqlist[i] = ls.count(i)

for i in range(q):
	a = qls[i][0]
	b = qls[i][1]
	if a in freqlist:
		temp = total - freqlist[a]*a
		temp += b * freqlist[a]
		print(temp)
		total = temp
		if b in freqlist:
			freqlist[b] += freqlist[a]
			freqlist.pop(a)
		else:
			k = freqlist.pop(a)
			freqlist[b] = k
	else:
		print(total)

