#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::pow;
using std::string;
using std::vector;
int main() {
  int N, Q, i, tmp;
  long long int out = 0;
  cin >> N;
  vector<int> a(1000000, 0);
  for (i = 0; i < N; i++) {
    cin >> tmp;
    a.at(tmp)++;
    out += tmp;
  }
  cin >> Q;
  vector<int> b(Q), c(Q);
  for (i = 0; i < Q; i++) cin >> b.at(i) >> c.at(i);
  for (i = 0; i < Q; i++) {
    tmp = a.at(b.at(i));
    out -= tmp * b.at(i);
    out += tmp * c.at(i);
    cout << out << endl;
    a.at(b.at(i)) = 0;
    a.at(c.at(i)) += tmp;
  }
}
