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

bc = [map(int, input().split()) for _ in range(q)]
b, c = [list(i) for i in zip(*bc)]

for i in range(q):
	ind = []
	ind  = [j for j, x in enumerate(a) if x == b[i]]
	l = len(ind)
	if l > 0:
		for k in range(l):
			a[ind[k]] = c[i]
		print(sum(a))
	else:
		print(sum(a))
	"""
	for j in range(n):
		if a[j] ==b[i]:
			a[j] = c[i]
	"""
