#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, b, c, d;
  long long int s = 0;
  int A[100010] = {};
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> d;
    A[d]++;
    s += d;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    s = s - A[b] * (b - c);
    cout << s << endl;
  }
}
