#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1);
int main(void) {
  int n;
  cin >> n;
  vector<int> a(1e5);
  for (int i = 0, i_len = (n); i < i_len; ++i) {
    int x;
    cin >> x;
    a.at(x)++;
  }
  int q;
  cin >> q;
  for (int z = 0, z_len = (q); z < z_len; ++z) {
    int qb, qc;
    cin >> qb >> qc;
    a.at(qc) += a.at(qb);
    a.at(qb) = 0;
    int ans = 0;
    for (int i = 0, i_len = (n); i < i_len; ++i) {
      ans += a.at(i) * (i + 1);
    }
    cout << ans << endl;
  }
  return 0;
}
