#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> 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);
  }
  map<int, int> ansA;
  for (int i = 0; i < N; i++) {
    if (ansA.count(a.at(i))) {
      ansA[a.at(i)]++;
    } else {
      ansA[a.at(i)] = 1;
    }
  }
  for (int i = 0; i < Q; i++) {
    if (ansA.count(b.at(i))) {
      if (ansA.count(c.at(i))) {
        ansA[c.at(i)] += ansA.at(b.at(i));
        ansA.erase(b.at(i));
      } else {
        ansA[c.at(i)] = ansA.at(b.at(i));
        ansA.erase(b.at(i));
      }
    }
    long long sum = 0;
    long long tmp;
    for (int i = 1; i < 100001; i++) {
      if (ansA.count(i)) {
        sum += i * ansA.at(i);
      }
    }
    cout << sum << endl;
  }
}
