#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  vector<pair<int, int>> an(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  cin >> q;
  sort(a.begin(), a.end());
  vector<pair<int, int>> bc(q);
  for (int i = 0; i < q; i++) {
    cin >> bc[i].first >> bc[i].second;
  }
  int num;
  map<int, int> c;
  for (int i = 0; i < q; i++) {
    num = (upper_bound(a.begin(), a.end(), bc[i].first) -
           lower_bound(a.begin(), a.end(), bc[i].first));
    c.insert(make_pair(bc[i].first, num));
  }
  for (int i = 0; i < q; i++) {
    sum += (bc[i].second - bc[i].first) * c[bc[i].first];
    c[bc[i].second] += c[bc[i].first];
    cout << sum << "\n";
  }
}
