#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (m.count(a) == 0) {
      m[a] = 1;
    } else {
      m.at(a)++;
    }
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int64_t sum = 0;
    int b, c;
    cin >> b >> c;
    if (m.count(b) == 0) {
      m[b] = 0;
    }
    if (m.count(c) == 0) {
      m[c] = 0;
      m.at(c) = m.at(b);
      m.at(b) = 0;
    } else {
      m.at(c) += m.at(b);
      m.at(b) = 0;
    }
    for (auto p : m) {
      auto k = p.first;
      auto v = p.second;
      sum += k * v;
    }
    cout << sum << endl;
  }
  return 0;
}
