#include <cstdio>
#include <cstring>
int buc[100001],n,q;
int main()
{
	scanf("%d",&n);long long sum=0;
	for(int i=1;i<=n;++i){int x;scanf("%d",&x);sum+=x;++buc[x];}scanf("%d",&q);
	while(q--)
	{
		int b,c;scanf("%d%d",&b,&c);sum-=1ll*buc[b]*b;sum+=1ll*buc[b]*c;
		buc[c]+=buc[b];buc[b]=0;printf("%lld\n",sum);
	}return 0;
}