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

typedef long long int ll;

ll arr[100005];

int main()
{
	ll n;
	cin>>n;
	ll a[n],sum=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		arr[a[i]]++;
		sum+=a[i];
	}
	ll q;
	cin>>q;
	for(ll i=0;i<q;i++)
	{
		ll b,c;
		cin>>b>>c;
		sum+=(c-b)*arr[b];
		printf("%lld\n",sum);
		arr[c]+=arr[b];
		arr[b]=0;
	}
}

