#include <bits/stdc++.h>
using namespace std;
signed main() {
  int N;
  cin >> N;
  multiset<int> A;
  for (int i = 0; i < N; i++) {
    int A_;
    cin >> A_;
    A.insert(A_);
  }
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  long long second = 0;
  for (auto i = A.begin(); i != A.end(); i++) {
    second += (*i);
  }
  for (int i = 0; i < Q; i++) {
    int count = A.count(B[i]);
    A.erase(B[i]);
    for (int j = 0; j < count; j++) {
      A.insert(C[i]);
    }
    second -= (count * (B[i] - C[i]));
    printf("%d\n", second);
  }
}
