#include <iostream>
using namespace std;
int main(void){
	long long n,v[100010],i,ans=0,temp,q,b,c;
	cin >> n;
	for (i=0 ; i<=100000; i++) {
		v[i] = 0;
	}
	for (i=0 ; i<n ; i++) {
		cin >> temp;
		ans += temp;
		v[temp]++;
	}
	cin >> q;
	for (i=0 ; i<q ; i++) {
		cin >> b >> c;
		ans += v[b] * (c-b);
		v[c] += v[b];
		v[b] = 0;
		cout << ans << '\n';
	}
}
