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