#include <bits/stdc++.h>
using namespace std;
int n, q, x, sum, num;
int a[100005], bi[100005], ci[100005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[x]++;
    sum += x;
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> bi[i] >> ci[i];
  }
  num = sum;
  for (int i = 1; i <= q; i++) {
    num += a[bi[i]] * (ci[i] - bi[i]);
    cout << num << endl;
    num = sum;
  }
}
