#include <bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
using ll = long long;
using d = double;

int main(){
  int N;
  cin >> N;
  ll M;
  // vector<int> A(N);
  vector<int> X(100005,0);
  rep(i,N){
    int a;
    cin >> a;
    // A.at(i) = a;
    M += a;
    X.at(i)++;
  }
  int Q;
  cin >> Q;
  vector<int> B(100005);
  vector<int> D(100005);
  rep(i,Q){
    int b,c;
    cin >> b >> c;
    // B.at(i) = b;
    // D.at(i) = c-b;
    M += X.at(b) * (c-b);
    cout << M << endl;
    int v = X.at(c)
    X.at(c) += X.at(b);
    X.at(b) -= v;
  }
//   for(int c: X){
//     if(X.at(c)>0){
//       M += X.at(c)*D.at(c);
//     }
//   }
}