#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vll = vector<ll>;
int main() {
  ll n, q, a, b, c, i, j, k, s = 0;
  cin >> n;
  multiset<ll> m;
  for (i = 0; i < n; i++) {
    cin >> a;
    m.insert(a);
    s += a;
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> b >> c;
    auto it = m.lower_bound(b);
    auto it2 = m.upper_bound(b);
    if (it != m.end()) {
      k = distance(it, it2);
      m.erase(b);
      s += (c - b) * k;
      for (j = 0; j < k; j++) m.insert(c);
    }
    cout << s << endl;
  }
}
