#include <bits/stdc++.h>
using namespace std;
long long binarySearch(long long arr[], long long l, long long r, long long x) {
  if (r < l) return -1;
  if (arr[r] == x) {
    return r;
  }
  long long mid = l + (r - l) / 2;
  if (arr[mid] == x) return mid;
  if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);
  return binarySearch(arr, mid + 1, r, x);
}
int main() {
  ios_base::sync_with_stdio(0);
  long long n, q, b, c, sum = 0;
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  sort(arr, arr + n);
  cin >> q;
  for (long long i = 0; i < q; i++) {
    cin >> b >> c;
    long long ans = binarySearch(arr, 0, n - 1, b);
    if (ans == -1) {
      cout << sum << endl;
    } else {
      long long count = 1;
      long long left = ans - 1;
      long long right = ans + 1;
      arr[ans] = c;
      while (left >= 0 && arr[left] == b) {
        count++;
        arr[left] = c;
        left--;
      }
      while (right < n && arr[right] == b) {
        count++;
        arr[right] = c;
        right++;
      }
      sum += count * (c - b);
      cout << sum << endl;
    }
  }
}
