#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int& Ai : A) {
    cin >> Ai;
  }
  int Q;
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (int i = 0; i < Q; ++i) {
    int bi, ci;
    cin >> bi >> ci;
    B[i] = bi;
    C[i] = ci;
  }
  unordered_map<int, vector<int>> locations;
  for (int i = 0; i < N; ++i) {
    locations[A[i]].push_back(i);
  }
  int sum = 0;
  for (int Ai : A) sum += Ai;
  for (int i = 0; i < Q; ++i) {
    int Bi = B[i];
    int Ci = C[i];
    if (Bi != Ci) {
      vector<int> locs = locations[Bi];
      locations[Bi].clear();
      int nl = locs.size();
      sum += nl * (Ci - Bi);
      for (int ii : locs) {
        A[ii] = Ci;
        locations[Ci].push_back(ii);
      }
    }
    cout << sum << endl;
  }
  return 0;
}
