#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
int main() {
  int n;
  cin >> n;
  ll a;
  std::map<ll, ll> map;
  for (int i = 0; i < int(n); i++) {
    cin >> a;
    if (map.count(a)) {
      map[a] += 1;
    } else {
      map[a] = 1;
    }
  }
  int q;
  cin >> q;
  ll b, c;
  for (int i = 0; i < int(q); i++) {
    cin >> b >> c;
    if (map.count(b)) {
      if (map.count(c)) {
        map[c] += map[b];
        map[b] = 0;
      } else {
        map[c] = map[b];
        map[b] = 0;
      }
    }
    ll ans = 0;
    for (auto const &[k, v] : map) {
      ans += k * v;
    }
    cout << ans << endl;
  }
}
