#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  multiset<int> target;
  for (int i = 0; i < N; i++) {
    int t;
    cin >> t;
    target.insert(t);
  }
  ll result = accumulate(target.begin(), target.end(), 0);
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int replace_before, replace_after;
    cin >> replace_before >> replace_after;
    int replace_count;
    replace_count = target.erase(replace_before);
    for (; 0 < replace_count; replace_count--) {
      target.insert(replace_after);
      result = result - replace_before + replace_after;
    }
    cout << result << endl;
  }
  return 0;
}
