#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) cin >> V.at(i);
  vector<int> M(100000);
  for (int I = 0; I < 100000; I++) M.at(I) = 0;
  for (int j = 0; j < N; j++) M.at(V.at(j))++;
  int Q;
  cin >> Q;
  vector<vector<int>> W(Q, vector<int>(2));
  for (int k = 0; k < Q; k++) cin >> W.at(k).at(0) >> W.at(k).at(1);
  int count = 0;
  for (int l = 0; l < N; l++) count += V.at(l);
  for (int m = 0; m < Q; m++) {
    count += M.at(W.at(m).at(0)) * (W.at(m).at(1) - W.at(m).at(0));
    cout << count << endl;
    M.at(W.at(m).at(1)) += M.at(W.at(m).at(0));
  }
}
