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