#include <bits/stdc++.h>
using namespace std;
int n, q, bi, ci;
long long tot;
vector<int> arr;
multiset<int> segments;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  arr.resize(n);
  for (int &x : arr) {
    cin >> x;
    segments.insert(x);
    tot += (long long)x;
  }
  cin >> q;
  while (q--) {
    cin >> bi >> ci;
    int qtd = segments.count(bi);
    if (qtd) {
      tot -= (long long)qtd * (long long)bi;
      tot += (long long)qtd * (long long)ci;
      segments.erase(bi);
      auto it = segments.insert(ci);
      for (int i = 1; i < qtd; i++) segments.insert(it, ci);
    }
    cout << tot << endl;
  }
}
