#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 5;
const int alength = 100100;
int main() {
  int n;
  cin >> n;
  map<int, int> a;
  for (int i = 0; i < n; ++i) {
    int hoge;
    cin >> hoge;
    auto itr = a.find(hoge);
    if (itr == a.end()) {
      a[hoge] = 1;
    } else {
      ++a[hoge];
    }
  }
  int q;
  cin >> q;
  int b[alength], c[alength];
  for (int i = 0; i < q; ++i) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; ++i) {
    auto itra = a.find(b[i]);
    if (itra != a.end()) {
      auto itrb = a.find(c[i]);
      if (itrb != a.end()) {
        a[c[i]] += a[b[i]];
      } else {
        a[c[i]] = a[b[i]];
      }
      a[b[i]] = 0;
    }
    unsigned long long ans = 0;
    for (const auto& [key, value] : a) {
      ans += value * key;
    }
    cout << ans << "\n";
  }
}
