#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int multi(int a, int b) { return int(a * 1ll * b % mod); }
int firstOcc(int *arr, int l, int h, int x) {
  if (h >= l) {
    int mid = (l + h) / 2;
    if ((mid == 0 || x > arr[mid - 1]) && arr[mid] == x)
      return mid;
    else if (x > arr[mid])
      return firstOcc(arr, (mid + 1), h, x);
    else
      return firstOcc(arr, l, (mid - 1), x);
  }
  return -1;
}
int lastOcc(int arr[], int n, int l, int h, int x) {
  if (h >= l) {
    int mid = (l + h) / 2;
    if ((mid == n - 1 || x < arr[mid + 1]) && arr[mid] == x)
      return mid;
    else if (x < arr[mid])
      return lastOcc(arr, n, l, (mid - 1), x);
    else
      return lastOcc(arr, n, (mid + 1), h, x);
  }
  return -1;
}
int occurrenceCnt(int *arr, int x, int n) {
  int idxFirst = firstOcc(arr, 0, n - 1, x);
  if (idxFirst == -1) {
    return -1;
  }
  int idxLast = lastOcc(arr, n, idxFirst, n - 1, x);
  return idxLast - idxFirst + 1;
}
void solve() {
  long long n;
  cin >> n;
  int a[n];
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  long long k;
  cin >> k;
  for (long long i = 0; i < k; i++) {
    long long c, b;
    cin >> c >> b;
    long long q = occurrenceCnt(a, c, n);
    if (b > c) {
      long long f = firstOcc(a, 0, n - 1, c);
      long long l = lastOcc(a, n, 0, n - 1, c);
      if (f != -1 && l != -1) {
        for (long long i = f; i <= l; i++) {
          a[i] = b;
        }
        sum = sum + q * (b - c);
      }
    } else {
      long long f = firstOcc(a, 0, n - 1, c);
      long long l = lastOcc(a, n, 0, n - 1, c);
      if (f != -1 && l != -1) {
        for (long long i = f; i <= l; i++) {
          a[i] = b;
        }
        sum = sum - q * (c - b);
      }
    }
    cout << sum << "\n";
  }
}
int main() { solve(); }
