#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0)->sync_with_stdio(false);
  ll n;
  cin >> n;
  map<ll, int> a;
  ll sum = 0;
  for (int i = 0; i < (n); i++) {
    ll tmp;
    cin >> tmp;
    sum += tmp;
    a[tmp]++;
  }
  ll q;
  cin >> q;
  vector<ll> b(q), c(q);
  for (int i = 0; i < (q); i++) cin >> b[i] >> c[i];
  for (int i = 0; i < (q); i++) {
    if (a.find(b[i]) != a.end()) {
      sum += a[b[i]] * (c[i] - b[i]);
      a[c[i]] += a[b[i]];
      cout << sum << '\n';
    } else {
      cout << sum << '\n';
    }
  }
  return 0;
}
