#include <bits/stdc++.h>
using namespace std;
int first(int arr[], int low, int high, int x, int n) {
  if (high >= low) {
    int mid = low + (high - low) / 2;
    if ((mid == 0 || x > arr[mid - 1]) && arr[mid] == x)
      return mid;
    else if (x > arr[mid])
      return first(arr, (mid + 1), high, x, n);
    else
      return first(arr, low, (mid - 1), x, n);
  }
  return -1;
}
int last(int arr[], int low, int high, int x, int n) {
  if (high >= low) {
    int mid = low + (high - low) / 2;
    if ((mid == n - 1 || x < arr[mid + 1]) && arr[mid] == x)
      return mid;
    else if (x < arr[mid])
      return last(arr, low, (mid - 1), x, n);
    else
      return last(arr, (mid + 1), high, x, n);
  }
  return -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int sum = 0;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  int q;
  cin >> q;
  sort(arr, arr + n);
  int b, c;
  while (q--) {
    cin >> b >> c;
    sort(arr, arr + n);
    int firstOc = first(arr, 0, n - 1, b, n);
    if (firstOc != -1) {
      int lastOc = last(arr, 0, n - 1, b, n);
      int multiplier = lastOc - firstOc + 1;
      sum = sum - (multiplier * b) + (multiplier * c);
      for (int i = firstOc; i <= lastOc; i++) {
        arr[i] = c;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
