#include<iostream>
//#include<vector>
#include <bits/stdc++.h> 

using namespace std;

int main(){
  long long N,val,sum = 0;
  cin >> N;
  //vector<long long> ival;
  multiset<long long> ival
  for(int i = 0; i < N ; i++){
    cin >> val;
    //ival.push_back(val);
    ival.insert(val);
    sum += val; 
  }
  
  long long Q,b,c;
  cin >> Q;
  
  for(int i = 0; i < Q ; i++){
    cin >> b;
    cin >> c;
    //vector<long long>::iterator it;
    //it = find (ival.begin(), ival.end(), b);
    if(ival.find(b) != ival.end()){
      int count = ival.count(b);
      ival.erase(b);
      for(int i= 0; i < count ; i++){
        ival.insert(c);
      }
      sum = sum -count*b + count*c;
    }
    
    cout<<sum<<'\n';
    
    //while(it != ival.end()){
    //  *it = c;
    //  it = find (ival.begin(), ival.end(), b);
    //}
    //cout<<accumulate(ival.begin(),ival.end(),0)<<'\n';
  }
  
}