#include <stdio.h>
#define LL long long
#define maxn 100010
LL sum,a[maxn],cnt[maxn];
int main(){
	int i,n,q,b,c;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]),sum+=a[i],cnt[a[i]]++;
	scanf("%d",&q);
	while(q--){
		scanf("%d%d",&b,&c);
		sum-=cnt[b]*b;
		sum+=cnt[b]*c;
		cnt[c]+=cnt[b],cnt[b]=0;
		printf("%lld\n",sum);
	}
	return 0;
}