#include <bits/stdc++.h>
using namespace std;

const int nm = 1e5;
int n, p[nm + 1], q;

int main() {
	cin >> n;
	long long s = 0;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		s += a;
		++p[a];
	}
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int b, c;
		cin >> b >> c;
		s += (long long) p[b] * (c - b);
		p[c] += p[b];
		p[b] = 0;
		cout << s << endl;
	}

}
