n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[0]*q
c=[0]*q
s=[0]*(q+1)
for i in range(q):
	b[i],c[i]=map(int,input().split())
f={}
for i in range(n):
	f.setdefault(a[i],[])
for i in range(n):
	f[a[i]].append(i)
for g,h in f.items():
	#print(len(h)*g)
	s[0]=s[0]+len(h)*g
#print(f)
for i in range(1,q+1):
	if b[i-1] in f:
		if c[i-1] in f:
			f[c[i-1]]=f[c[i-1]]+f[b[i-1]]
			s[i]=s[i-1]-len(f[b[i-1]])*b[i-1]
			#print(s[i])
			
			s[i]=s[i]+len(f[b[i-1]])*c[i-1]
			f.pop(b[i-1])
		else:
			f.setdefault(c[i-1],[])
			f[c[i-1]]=f[c[i-1]]+f[b[i-1]]
			s[i]=s[i-1]-len(f[b[i-1]])*b[i-1]
			#print(s[i])
			
			s[i]+=len(f[b[i-1]])*c[i-1]
			f.pop(b[i-1])
	#print(f)
	#for g,h in f.items():
		#print(len(h)*g)
		#s[i]=s[i]+len(h)*g
	else:
		s[i]=s[i-1]
	print(s[i])
