#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll arr[100001];
ll  sum=0;
int main(){

	ll n;	cin>>n;
	
	for(int i=0; i<n; i++){
		int a;	cin>>a;
		sum+=a;
		arr[a]++;
	}
	ll q;
	cin>>q;
	while(q--){
		int a, b;
		cin>>a>>b;
		ll d = a*arr[a];
		sum-=d;
		sum+=(b*arr[a]);
		arr[b]+=arr[a];
		arr[a] = 0;
		cout<<sum<<endl;
	}


return 0;
}