#include <bits/stdc++.h> 
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i){
    cin >> A.at(i);
  }
  //sort(A.begin(), A.end());
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for(int i = 0; i < Q; ++i){
    cin >> B.at(i) >> C.at(i);
  }
  /*
  for (int i = 0; i < Q; ++i){
    vector<int>::iterator it_s = lower_bound(A.begin(),A.end(),B.at(i));
    vector<int>::iterator it_e = upper_bound(A.begin(),A.end(),B.at(i));
    for(vector<int>::iterator itr = it_s; itr < it_e; ++itr){
      *itr = C.at(i);
    }
    cout << accumulate(A.begin(), A.end(), 0) << endl;
  }
  */
  vector <int> count(10*10*10*10*10 + 1, 0);
  for(int i = 0; i < A.size(); ++i){
    ++count.at(A.at(i));
  }
  long long sum = accumulate(A.begin(), A.end(), 0);
  for(int i = 0; i < Q; ++i){
    sum += (long long)(C.at(i) * count.at(B.at(i))) - (long long)(B.at(i) * count.at(B.at(i)));
    count.at(C.at(i)) += count.at(B.at(i));
    count.at(B.at(i)) = 0;
    cout << sum << endl;
  }
}

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; ++i){
    cin >> A.at(i);
  }
  //sort(A.begin(), A.end());
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for(int i = 0; i < Q; ++i){
    cin >> B.at(i) >> C.at(i);
  }
  /*
  for (int i = 0; i < Q; ++i){
    vector<int>::iterator it_s = lower_bound(A.begin(),A.end(),B.at(i));
    vector<int>::iterator it_e = upper_bound(A.begin(),A.end(),B.at(i));
    for(vector<int>::iterator itr = it_s; itr < it_e; ++itr){
      *itr = C.at(i);
    }
    cout << accumulate(A.begin(), A.end(), 0) << endl;
  }
  */
  vector <int> count(10*10*10*10*10 + 1, 0);
  for(int i = 0; i < A.size(); ++i){
    ++count.at(A.at(i));
  }
  long long sum = accumulate(A.begin(), A.end(), 0);
  for(int i = 0; i < Q; ++i){
    sum += (long long)(C.at(i) * count.at(B.at(i))) - (long long)(B.at(i) * count.at(B.at(i)));
    count.at(C.at(i)) += count.at(B.at(i));
    count.at(B.at(i)) = 0;
    cout << sum << endl;
  }
}
