#include <iostream>
using namespace std;

int main() {
	long long n;
	cin>>n;
	long long i,p,q,r,sum=0;
	long long arr[100001]={0};
	for(i=0;i<n;i++)
	{
	cin>>p;
	arr[p]++;
	sum+=p;
	}
	cin>>q;
	while(q--)
	{
cin>>p>>r;
sum=sum-(arr[p]*p);
sum=sum+(arr[p]*r);
arr[r]=arr[r]+arr[p];
arr[p]=0;
	cout<<sum<<"\n";
		
	}
	
		
		
	
	// your code goes here
	return 0;
}