#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;
template <class TYPE>
struct edge {
  TYPE to, cost;
  edge(TYPE t, TYPE c) {
    to = t;
    cost = c;
  }
};
int main() {
  long long N;
  cin >> N;
  int a[100001];
  long long sum = 0;
  for (int i = 1; i <= 100000; i++) a[i] = 0;
  for (int i = 0; i < N; i++) {
    int b;
    cin >> b;
    sum += b;
    a[b]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    if (a[b] == 0)
      cout << sum << endl;
    else {
      cout << sum + a[b] * (c - b) << endl;
    }
  }
  return 0;
}
