#include<iostream>
#include<vector>
#include <bits/stdc++.h> 
using namespace std;
int main(){
  long long N;
  long long val;
  cin >> N;
  vector<long long> ival;
  
  for(int i = 0; i < N ; i++){
    cin >> val;
    ival.push_back(val);
  }
  
  long long Q,b,c;
  cin >> Q;
  vector<long long>::iterator it;
  
  for(int i = 0; i < Q ; i++){
    cin >> b;
    cin >> c;
    
    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';
    long long sum = 0;
    for(int i = 0; i < ival.size() ; i++){
      sum += ival[i]
    }
    cout<<sum<<'\n';
  }
  
}