#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  long long a[n], s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  sort(a, a + n);
  cin >> q;
  long long b[q], c[q];
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
    int u = upper_bound(a, a + n, b[i]) - a;
    int l = lower_bound(a, a + n, b[i]) - a;
    if ((u - l) > 0) {
      s = s - ((u - l) * b[i]) + ((u - l) * c[i]);
      for (int j = l; j < u; j++) a[j] = c[i];
      sort(a, a + n);
    }
    cout << s << endl;
  }
}
