#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, q, sum, a, b, c, count;
  cin >> n;
  long long int arr[n];
  sum = 0;
  for (a = 0; a < n; a++) {
    cin >> arr[a];
    sum += arr[a];
  }
  sort(arr, arr + n);
  cin >> q;
  while (q--) {
    cin >> b >> c;
    count = 0;
    for (a = 0; arr[a] <= b; a++) {
      if (b == arr[a]) {
        arr[a] = c;
        count++;
      }
    }
    sum += (count * (c - b));
    cout << sum << endl;
    sort(arr, arr + n);
  }
  return 0;
}
