#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  multiset<long long> s;
  long long n;
  cin >> n;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    sum += a;
    s.insert(a);
  }
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    int sz = (int)s.size();
    s.erase(b);
    int new_sz = (int)s.size();
    long long diff = sz - new_sz;
    sum -= diff * b;
    sum += diff * c;
    for (int i = 0; i < diff; i++) s.insert(c);
    cout << sum << '\n';
  }
}
