#include<bits/stdc++.h>
#define int long long
using namespace std;
int times[100001],n,q,sum;
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%lld",&x);
		times[x]++;
		sum+=x;
	}
	scanf("%lld",&q);
	while(q--)
	{
		int x,y;
		scanf("%lld%lld",&x,&y);
		sum+=(y-x)*times[x];
		cout<<sum<<endl;
		times[y]+=times[x];
		times[x]=0;
	}
	return 0;
}