#include <bits/stdc++.h>
using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX(1LL << 60);
const ll MOD(1000000007);
using namespace std;
using T = tuple<ll, ll>;
using Graph = vector<vector<T>>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, q;
  cin >> n;
  vector<ll> a(n);
  for (ll i = (0); i < (n); i++) cin >> a[i];
  cin >> q;
  vector<ll> b(q), c(q);
  for (ll i = (0); i < (q); i++) cin >> b[i] >> c[i];
  ll accm(0);
  for (ll i = (0); i < (n); i++) accm += a[i];
  for (ll i = (0); i < (q); i++) {
    sort(a.begin(), a.end());
    auto iter = lower_bound(a.begin(), a.end(), b[i]);
    ll j = distance(a.begin(), iter);
    ll org(a[j]);
    ll num_change(0);
    while (a[j] == b[i]) {
      a[j] = c[i], ++j, num_change++;
    }
    accm += (c[i] - org) * num_change;
    cout << accm << endl;
  }
  return 0;
}
