#include <vector> 
#include <map>
#include <queue>
#include <iostream>
#include <iterator>
#define pb push_back 
#define int long long
using namespace std; 

int main() 
{ 
	int n,q,s=0; 
	cin >> n; 
	vector<int> v(100069,0); 
	for(int i=0, t;i<n;i++)
	{
		cin >> t;
		v[t]++;
		s+=t;
	}
	cin >> q;
	int b, c; 
	while(q--) { 
		cin >> b >> c; 
		s-=v[b]*b;
		s+=v[b]*c;	
		v[c]+=v[b];
		v[b]=0;
		cout<<s<<"\n";
		
	} 

	

	return 0; 
} 
