n=int(input())
l=list(map(int,input().split()))
freq={}
for i in range(n):
	freq[l[i]]=0
for i in range(n):
	freq[l[i]]+=1
t=int(input())
for i in range(t):
	a,b=map(int,input().split())
	if(a not in freq.keys()):
		sm=0
		for x, y in freq.items():
			sm+=(x*y)
		print(sm)
	else:
		if(b not in freq.keys()):
			freq[b]=0
		freq[b]+=freq[a]
		freq[a]=0
		sm=0
		for x, y in freq.items():
			sm+=(x*y)
		print(sm)
