#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  long long int a[t];
  long long int sum = 0;
  for (int i = 0; i < t; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long int aa, b;
    cin >> aa >> b;
    int k = lower_bound(a, a + t, aa) - a;
    int kk = upper_bound(a, a + t, aa) - a;
    kk = kk - 1;
    int count = kk - k + 1;
    sum = sum - (count * aa) + (count * b);
    cout << sum << "\n";
    for (int j = 0; j < count; j++) {
      long long int m = b;
      swap(a[k + j], m);
    }
  }
}
