n=int(input())
c=list(map(int,input().split()))
q=int(input())
su=0
w={}
for i in range(len(c)):
	su=su+c[i]
	if(c[i] not in w):
		w[c[i]]=1
	else:
		w[c[i]]=w[c[i]]+1
for j in range(q):
	r,s=map(int,input().split())
	count=w[r]
	if(s in w):
		w[s]=w[s]+count
	else:
		w[s]=count
	su=su-count*r+count*s
	print(su)

