#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);
const ll sch = 200000;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main(void) {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll n, q, sum;
  cin >> n;
  map<ll, ll> a;
  set<ll> conf;
  for (int i = 0; i < (int)n; ++i) {
    int k;
    cin >> k;
    if (conf.count(k)) {
      a[k]++;
    } else {
      a[k] = 1;
    }
    conf.insert(k);
    sum += k;
  }
  cin >> q;
  vector<ll> b(q), c(q);
  for (int i = 0; i < (int)q; ++i) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < (int)q; ++i) {
    if (conf.count(b[i])) {
      sum += (c[i] - b[i]) * a[b[i]];
      if (conf.count(c[i])) {
        a[c[i]] += a[b[i]];
      } else {
        a[c[i]] = a[b[i]];
      }
      a.erase(b[i]);
      conf.erase(b[i]);
      conf.insert(c[i]);
    }
    cout << sum << endl;
  }
  return 0;
}
