#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  for (long long i = 0; i < A.size(); ++i) cin >> A[i];
  ;
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (long long i = 0; i < B.size(); ++i) cin >> B[i] >> C[i];
  ;
  int sum_array = accumulate(A.begin(), A.end(), 0);
  for (int i = 0; i < (int)(Q); i++) {
    sort(A.begin(), A.end());
    auto min_pos = lower_bound(A.begin(), A.end(), B.at(i));
    auto max_pos = upper_bound(A.begin(), A.end(), B.at(i));
    for (auto itr = min_pos; itr != max_pos; ++itr) {
      *itr = C.at(i);
    }
    sum_array += distance(min_pos, max_pos) * (C.at(i) - B.at(i));
    cout << sum_array << endl;
  }
  return 0;
}
