#include <iostream>
#include <vector>
#onclude <alogrithm>
using namespace std;

int main() {
	int n = 0;
	cin >> n;
	vector <int> vect(n);
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> vect[i];
		sum = sum + vect[i];
	}
	int q = 0;
	cin >> q;
	int t1 = 0;
	int t2 = 0;
	sort(vect.begin(),vect.end());
	for (int i = 0; i < q; i++)
	{
		cin >> t1 >> t2;
		for (int j = 0; j < vect.size();j++)
		{
			if (vect[j] == t1)
			{
				vect[j] = t2;
				sum = sum - t1 + t2;
			}
		}
		cout << sum << endl;
	}
	return 0;
}