#include <bits/stdc++.h>
using namespace std;
int64_t sum_out(vector<int> &count) {
  int64_t sum = 0;
  for (int64_t i = 0; i < count.size(); i++) {
    sum += count.at(i) * (i + 1);
  }
  return sum;
}
int main() {
  int N;
  cin >> N;
  vector<int> count(10000, 0);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    count.at(a - 1)++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    count.at(c - 1) += count.at(b - 1);
    count.at(b - 1) = 0;
    cout << sum_out(count) << endl;
  }
  return 0;
}
