#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int pos1 = lower_bound(a, a + n, x) - a;
    int pos2 = upper_bound(a, a + n, x) - a;
    cout << sum - (pos2 - pos1) * x + (pos2 - pos1) * y << endl;
    sum = sum - (pos2 - pos1) * x + (pos2 - pos1) * y;
    fill(a + pos1, a + pos2, y);
    sort(a, a + n);
  }
}
