#include <iostream>

using namespace std;

int N;
long long sum;
int cnt[100005];
int Q;

int main()
{
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		int A;
		cin >> A;
		sum += A;
		cnt[A]++;
	}
	for (cin >> Q; Q--; )
	{
		int B, C;
		cin >> B >> C;
		sum -= 1LL * B * cnt[B];
		sum += 1LL * C * cnt[B];
		cnt[C] += cnt[B];
		cnt[B] = 0;
		cout << sum << endl;
	}
	return 0;
}