#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, m = 0;
  cin >> n;
  long int a[n];
  vector<int> v(100000, 0);
  for (long int i = 0; i < n; i++) {
    cin >> a[i];
    m += a[i];
    v[a[i]]++;
  }
  long int q;
  cin >> q;
  for (long int i = 0; i < q; i++) {
    long int b, c;
    cin >> b >> c;
    long int d = c - b;
    cout << m + d * v[b] << "\n";
  }
}
