#include <stdio>

int main(){
	ll n, q,sum = 0;
	ll b,c;
	scanf("%d", &q);
	ll a[10000];
	memset(a, 0, sizeof(a));
	for(int i = 0; i<n; i++)
		scanf("%d", &a[i]);
	
	scanf("%d", &q);
	while(q--){
		scanf("%d%d", &b, &c); 
		for(int j = 0; j<n; j++){
			if(a[j] == b)a[j] = c;
			sum +=a[j]; 
		}
		printf("%d\n", sum);
		sum = 0;
	
	}
	
	

return 0;
}
