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

#define in_fre freopen("redir.txt", "r", stdin);
#define out_fre freopen("out5.txt", "w", stdout);
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define debug(i) printf("\nDebug %d\n",i);
#define mod 1000000007
#define ll long long int

int main()
{	
clock_t begin, end;
double time_spent;
begin = clock();

//	fast();
#ifndef ONLINE_JUDGE
	in_fre
	out_fre
#endif

ll n;
cin>>n;
ll ar[n]={0},br[100005]={0},sum=0;
for (int i = 0; i < n; ++i)
{cin>>ar[i];br[ar[i]]++;sum+=ar[i];
}
ll q;
cin>>q;
for (int i = 0; i < q; ++i)
{ ll b,c;
	cin>>b>>c;
	//if(br[b]!=0)
	{
		sum=sum-br[b]*b+br[b]*c;
		cout<<sum<<"\n";
		//br[b]=0;
		br[c]=br[c]+br[b];
		br[b]=0;
	}
}

end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
cerr<<"Time spent = "<<time_spent<<endl;

return 0;
}