#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  map<int, int> cnt;
  for (int i = 0; i < n; i++) {
    cnt[a[i]]++;
  }
  vector<int> ans(q, 0);
  for (int i = 0; i < q; i++) {
    if (cnt.count(b[i])) {
      cnt[c[i]] += cnt[b[i]];
      cnt.erase(b[i]);
    }
    for (auto [k, cn] : cnt) {
      ans[i] += k * cn;
    }
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
