#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long

ll n, q, a[100001], s;

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		a[x]++;
		s += x;
	}

	cin >> q;

	for (int i = 0; i < q; i++)
	{
		int b, c;
		cin >> b >> c;

		s -= b * a[b];
		s += c * a[b];
		a[c] += a[b];
		a[b] = 0;
		
		cout << s << endl;
	}
}