#include<bits/stdc++.h>
#define MAXN 100001
int n,q,time[MAXN];
long long ans;
int main()
{
	cin>>n;
	for(int i=1,x;i<=n;++i)
	{
		cin>>x;
		ans+=x;
		++time[x];
	}
	cin>>q;
	for(int i=1,b,c;i<=q;++i)
	{
		cin>>b>>c;0
		ans-=1ll*time[b]*b;
		ans+=1ll*time[b]*c;
		cout<<ans;
		time[c]+=time[b];
		time[b]=0;
	}
	return 0;
}