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