#include"bits/stdc++.h"

#define rep(i, N) for(int i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

#define int long long

unsigned main(void) {

	map<int, int> m;

	int N, Q;
	cin >> N;
	vector<int> A(N);
	rep(i, N) {
		cin >> A[i];
		m[A[i]]++;
	}


	cin >> Q;

	vector<int> B(Q), C(Q);
	rep(i, Q) {
		cin >> B[i];
		cin >> C[i];
	}

	rep(i, Q) {
		int temp = m[B[i]];
		m[C[i]] += temp;
		m[B[i]] = 0;

		int sum = 0;
		for (auto x : m)sum += x.first * x.second;
		cout << sum << endl;
	}

	return 0;
}