n = int(input())
a = list(map(int, input().split()))
q = int(input())

b = []
c = []
for i in range(q):
	B, C = map(int, input().split())
	b.append(B)
	c.append(C)

a1 = []
a2 = []

for i in a:
	if i in a1:
		a2[a1.index(i)]+=1
	else:
		if i in b:
			a1.insert(0,i)
			a2.insert(0,1)
		else:
			a1.append(i)
			a2.append(1)

ans = []
s = 0

for i in range(len(a1)):
	s += a1[i]*a2[i]

ans.append(s)

for i in range(q):
	if b[i] in a1:
		bi = a1.index(b[i])
		if c[i] in a1:
			a2[a1.index(c[i])]+=a2[bi]
			ans.append(ans[-1]+a2[bi]*(c[i]-b[i]))
			a2[bi] = 0
		else:
			a1.append(c[i])
			a2.append(a2[bi])
			ans.append(ans[-1]+a2[bi]*(c[i]-b[i]))
			a2[bi] = 0
	else:
		ans.append(ans[-1])

for i in range(len(ans)-1):
	print(ans[i+1])