#include <bits/stdc++.h>
using namespace std;
int main() {
  uint64_t N, Q;
  cin >> N;
  unordered_map<uint64_t, int> hmap;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    if (hmap.find(a) != hmap.end())
      hmap[a] += 1;
    else
      hmap[a] = 1;
  }
  cin >> Q;
  vector<uint64_t> ans(Q);
  for (int i = 0; i < Q; ++i) {
    int b, c;
    cin >> b >> c;
    hmap[c] += hmap[b];
    hmap.erase(hmap.find(b));
    ans[i] = 0;
    for (auto &p : hmap) {
      ans[i] += p.first * p.second;
    }
  }
  for (int i = 0; i < Q; ++i) cout << ans[i] << "\n";
  return 0;
}
