#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n, sum = 0;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    sum += v[i];
  }
  sort((v).begin(), (v).end());
  int k;
  cin >> k;
  int lsum = sum;
  while (k--) {
    int x, y;
    cin >> x >> y;
    int mycount = count((v).begin(), (v).end(), x);
    lsum += mycount * (y - x);
    cout << lsum << '\n';
    replace((v).begin(), (v).end(), x, y);
  }
}
