#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  long long s = 0;
  cin >> N;
  vector<int> A(N);
  vector<int> ap(10 * 10 * 10 * 10 * 10);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    s += A.at(i);
    ap.at(A.at(i))++;
  }
  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++) {
    s += ap.at(b.at(i)) * (long)(c.at(i) - b.at(i));
    ap.at(c.at(i)) += ap.at(b.at(i));
    ap.at(b.at(i)) = 0;
    cout << s << endl;
  }
}
