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

typedef long long ll;

const int N = 1e5+10;

ll a[N];
ll freq[N];

int main()	
{
	int x,y,n,m;
	ll sum = 0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum += a[i];
		freq[a[i]]++;
	}
	cin>>m;
	while(m--){
		cin>>x>>y;
		sum -= 1ll*x*freq[x];
		sum += 1ll*y*freq[x];
		freq[y] += freq[x];
		freq[x] = 0;
		cout<<sum<<'\n';
	}

}