#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long ll
ll main(){
  ll f[100001]={0};
  ll n;
  cin>>n;
  for(ll i=0; i<n; i++){
  	ll temp; cin>>temp;
  	f[temp]++;
  }
  ll sum = 0;
  for(ll i=0; i<100001; i++){
  	sum+=(i*f[i]);
  }
  ll q;
  cin>>q;
  for(ll i=0; i<q; i++){
  	ll b,c;
  	cin>>b>>c;
  	ll freq = f[b];
  	f[b]=0;
  	f[c]+=freq;
  	sum = sum-freq*b+freq*c;
  	cout<<sum<<'\n';
  }
  return 0;
}