#include <bits/stdc++.h>
#include <ctype.h>
#include <string>
#include <math.h>
#include <iomanip> 
#include <queue>
using namespace std;

int main(){

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false); 

	
	int n, sum = 0;
	cin >> n;
	int a[n] = {0};
	int count[100001] = {0};
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		sum+=a[i];
		count[a[i]]++;
	}

	//for (int i = 0; i <= n; i++){
	//	cout << count[i] << " ";
	//}
	
	int q;
	cin >> q;
	for (int i = 0; i < q; i++){
		int b, c;
		cin >> b >> c;
		sum-=b * count[b];
		sum+=c * count[b];
		count[c]+= count[b];
		count[b] = 0;
		cout << sum << endl;
	}
	

}