#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	long int n,q,a[100000],b[100000],c[100000],i,j,k,sum=0;
	scanf("%ld",&n);
	for(i=0;i<n;i++){
		scanf("%ld",&a[i]);
	}
	scanf("%ld",&q);
	for(i=0;i<q;i++){
		scanf("%ld %ld",&b[i],&c[i]);
	}
	for(i=0;i<q;i++){
		for(j=0;j<n;j++){
			if(a[j] == b[i]) a[j] = c[i];
		}
		sum = 0;
		for(k=0;k<n;k++){
			sum = sum +a[k];
		}
	
		printf("%ld"\n,sum);
	}
	
	return 0;
}