#include <bits/stdc++.h>
using namespace std;
const int mx = 10001;
int main() {
  int n;
  long long sum = 0;
  cin >> n;
  vector<long long> d(mx);
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    d[a]++;
  }
  for (int i = 0; i < (int)(mx); i++) sum += i * d[i];
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    sum += (c - b) * d[b];
    cout << sum << endl;
  }
}
