#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, q, a, b, s, x;
vector<ll> v(100005);
int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i){
		cin >> x;
		++v[x];
		s += x;}
	cin >> q;
	while (q--)
	{
		cin >> a >> b;
		s -= (v[a] * a);
		s += (v[a] * b);
		v[b] += v[a], v[a] = 0;
		cout << s << "\n";
	}
	return 0;
}
