#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, q, ans = 0;
  string s;
  bool flag = false;
  cin >> n;
  vector<long long> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  vector<pair<long long, long long>> x(q);
  for (long long int i = 0; i < q; i++) cin >> x[i].first >> x[i].second;
  vector<vector<long long>> list(100000);
  for (long long int i = 0; i < n; i++) {
    list[a[i] - 1].push_back(i);
  }
  for (long long int i = 0; i < n; i++) {
    ans += a[i];
  }
  for (long long int i = 0; i < q; i++) {
    long long int diff = x[i].second * list[x[i].first - 1].size() -
                         x[i].first * list[x[i].first - 1].size();
    for (long long int j = 0; j < list[x[i].first - 1].size(); j++) {
      list[x[i].second - 1].push_back(
          list[x[i].first - 1][list[x[i].first - 1].size() - j - 1]);
      list[x[i].first - 1].pop_back();
    }
    ans += diff;
    cout << ans << "\n";
  }
}
