#include <iostream>
#define ll long long
using namespace std;


int main() {
	ll n;
	cin>>n;
	ll h[100005]={0};
	ll s=0;
	for(ll i=0;i<n;i++)
	{
       ll x;
       cin>>x;
       s+=x;
       h[x]++;
	}
	ll q;
	cin>>q;
	while(q--)
	{
		ll l,r;
		cin>>l>>r;
		s+=((r-l)*h[l]);
		h[r]+=h[l];
		h[l]=0;
		cout<<s<<endl;
	}
	return 0;
}
