#include <vector> 
#include <map>
#include <queue>
#include <iostream>
#include <iterator>
#include "bits/stdc++.h"
#define int long long
#define all(c) (c).begin(), (c).end()
#define cpresent(c,x) ((c).find(x) != (c).end()) 
#define vpresent(c,x) (find(all(c),x) != (c).end())
#define endl '\n'
#ifdef LOCAL
#include "/home/iggaboi/Desktop/CP/debug.h"
#else
#define debug(x...)
#endif
#define pb push_back 

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; 
	for (int i = 0; i < q; i++) { 
		cin>>b>>c; 
		s-=v[b]*b;
		s+=v[b]*c;	
		v[c]+=v[b];
		v[b]=0;
		cout<<s<<"\n";
		
	} 

	

	return 0; 
} 
