#include<iostream>
#include<cstdio>
#include<algorithm>
#include<stack>
using namespace std;
typedef long long ll;
ll sum=0,b[100001]={0};
int main(){
	ll n,t,k,j;
	cin>>n;
	while(n--){
		cin>>t;
		b[t]++;
		sum+=t;
	}
	cin>>t;
	while(t--){
		cin>>k>>j;
		ll s=j-k;
		sum+=(b[k]*s);
		b[j]+=b[k];
		b[k]=0;
		cout<<sum<<endl;
	}
}