#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A;
  A.resize(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  int Q;
  cin >> Q;
  vector<int> B, C;
  B.resize(Q);
  C.resize(Q);
  for (int i = 0; i < Q; i++) cin >> B[i] >> C[i];
  map<int, int> m;
  for (int i = 0; i < A.size(); i++) m[A[i]]++;
  for (int i = 0; i < B.size(); i++) {
    auto itr = m.find(B[i]);
    if (itr != m.end()) {
      m[C[i]] += itr->second;
      m.erase(itr);
    }
    long long ans = 0;
    for (auto itr = m.begin(); itr != m.end(); itr++) {
      ans += ((long long)itr->first * (long long)itr->second);
    }
    cout << ans << endl;
  }
  return 0;
}
