#include <iostream>
using namespace std;
long long s,n,i,b[100001],a,l,r,q;
int main()
{
	cin >> n;
	for ( i = 0 ; i < n ; i++ )
	{
		cin >> a;
		b[a]++;
		s+=a;
	}
	cin >> q;
	for ( i = 0 ; i < q ; i++ )
	{
		cin >> l >> r;
		b[r]+=b[l];
		s+=b[l]*(r-l);
		b[l] = 0;
		cout << s << endl;
	}
}