#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n;
  cin >> n;
  vector<long long> a;
  a.resize(n);
  long long sum = 0;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a.begin(), a.end());
  long long q;
  cin >> q;
  vector<pair<long long, long long>> b;
  for (long long i = 0; i < q; ++i) {
    long long x;
    cin >> x;
    long long y;
    cin >> y;
    b.push_back(make_pair(x, y));
  }
  unordered_map<long long, long long> freq;
  for (long long i = 0; i < n; ++i) {
    freq[a[i]]++;
  }
  for (long long i = 0; i < q; ++i) {
    long long f = freq[b[i].first];
    sum += (b[i].second - b[i].first) * f;
    freq[b[i].second] += f;
    cout << sum << '\n';
  }
  return 0;
}
