include <iostream>
#include <vector>
#include <numeric>

using ll = long long;
using namespace std;

int main()
{
	int N,Q;
	cin >> N;
	vector<int> A(N);
	vector<int> dp(100001);

	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}

	cin >> Q;

	auto sum_ll = accumulate(A.begin(),A.end(), 0LL);
	size_t n_count_B;
	size_t n_count_C;

	int B, C;
	for (int i = 0; i < Q; i++) {
		cin >> B >> C;
		if (dp.at(B)) {
			n_count_B = dp.at(B);
		}
		else {
			n_count_B = count(A.begin(), A.end(), B);
		}

		if (dp.at(C)) {
			n_count_C = dp.at(C);
		}
		else {
			n_count_C = count(A.begin(), A.end(), C);
		}

		sum_ll = sum_ll + C*n_count_B - B*n_count_B;

		dp.at(B) = 0;
		dp.at(C) = n_count_C + n_count_B;

		cout << sum_ll << endl;
	}

	return 0;
}