#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
typedef long double lld;
const ll INF = 1e18;
const ll MOD = 1e9+7;
 
ll fastpowMOD(ll a, ll p,ll MOD);
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; a %= MOD; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
 
ll lcm(ll a,ll b){
	return (a*b)/__gcd(a,b);
}

void solve(){
	ll n,q;
	cin>>n;
	vector<ll> a(q,0);
	map<ll,ll> mp;
	ll s = 0;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		s += a[i];
		mp[a[i]]++;
	}
	cin>>q;
	for(ll i=0;i<q;i++){
		ll x1,x2;
		cin>>x1>>x2;
		s -= x1*mp[x1];
		s += x2*mp[x1];
		mp[x2] += mp[x1];
		mp[x1] = 0;
		cout<<s<<"\n";
	}
	
}

int main(){
    fastio;
    int t;
    //cin>>t;
    t = 1;
    for(int i=1;i<=t;i++)
	solve();
	
}


