#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	ll n;
	vector<int> cnt(100001);
	cin >> n;
	ll ans = 0;
	for(ll i =0;i<n;i++)
	{
		ll x;
		cin >> x;
		cnt[x]++;
		ans += x;
	}
	ll q;
	cin >> q;
	while (q--)
	{
		ll x,y;
		cin >> x >> y;
		ans -= x*cnt[x];
		ans += y*cnt[x];
		cnt[y] += cnt[x];
		cnt[x] = 0;
		cout<<ans<<endl;
	}
	
}