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

const int N=1e5+20;

int n,q,x,y,f[N];
long long ans;

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&x);
		f[x]++;
		ans+=x;
	}

	scanf("%d",&q);
	while(q--)
	{
		scanf("%d%d",&x,&y);
		ans-=1ll*f[x]*x;
		ans+=1ll*f[x]*y;
		f[y]+=f[x];
		f[x]=0;
		
		printf("%lld\n",ans);
	}
}