#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  vector<ll> cnt(n + 1, 0);
  ll Max = 0;
  for (ll i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    ans += tmp;
    Max = max(Max, tmp);
    cnt[tmp]++;
  }
  ll q;
  cin >> q;
  vector<ll> res;
  for (ll i = 0; i < q; i++) {
    ll x, y;
    cin >> x >> y;
    if (x > Max) {
      res.push_back(ans);
      continue;
    }
    ans -= x * cnt[x];
    ans += y * cnt[x];
    cnt[y] += cnt[x];
    res.push_back(ans);
  }
  for (ll i = 0; i < (ll)res.size(); i++) {
    cout << res[i] << endl;
  }
}
