#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MX = 100005;
int main() {
  int n;
  cin >> n;
  vector<ll> cnt(MX);
  for (int i = 0; i < (n); ++i) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  ll tot = 0;
  for (int i = 0; i < (MX); ++i) tot += i * cnt[i];
  int q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    tot += (c - b) * cnt[b];
    cout << tot << endl;
  }
  return 0;
}
