#include<iostream>
#include<vector>
#include <bits/stdc++.h> 
using namespace std;
int main(){
  long long N,val,sum=0;
  cin >> N;
  vector<long long> cnt(1e5+10,0);
  
  for(int i = 0; i < N ; i++){
    cin >> val;
    cnt[val]++;
    sum += val
  }
  
  long long Q,b,c;
  cin >> Q;
  
  for(int i = 0; i < Q ; i++){
    cin >> b;
    cin >> c;
    if(cnt[b] > 0){
      cnt[c] += cnt[b];
      cnt[b] = 0;
    }
    //vector<long long>::iterator it;
    //it = find (ival.begin(), ival.end(), b);
    
    //while(it != ival.end()){
      //*it = c;
      //it = find (ival.begin(), ival.end(), b);
    //}
    //cout<<accumulate(ival.begin(),ival.end(),0)<<'\n';
    cout<<sum<<'\n';
  }
  
}