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

int main() {
    int N; cin >> N;
	vector<long long> A(100100, 0);
	long long sum = 0;
	for(int i=0; i<N; ++i) {
	    long long a; cin >> a;
		A[a] += 1;
		sum += a;
	}

	int Q; cin >> Q;
	while(Q--) {
	    long long b,c; cin >> b >> c;
		sum += (c - b) * A[b];
		A[c] += A[b];
		A[b] = 0;

		cout << sum << '\n';
	}
}
