#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  multiset<int> A;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    A.insert(a);
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int B, C;
    cin >> B >> C;
    int counter = A.erase(B);
    for (int i = 0; i < counter; ++i) {
      A.insert(C);
    }
    cout << accumulate(A.begin(), A.end(), 0) << endl;
  }
  return 0;
}
