#include <bits/stdc++.h>
using namespace std;
int sum(const vector<int>& vec) {
  int sum = 0;
  for (int i = 0; i < 10001; ++i) {
    sum += vec.at(i) * i;
  }
  return sum;
}
int main() {
  const int max = 10001;
  vector<int> vec(max);
  int N, A;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A;
    vec.at(A)++;
  }
  int Q, B, C;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    cin >> B >> C;
    int& b = vec.at(B);
    int& c = vec.at(C);
    if (b > 0) {
      c += b;
      b = 0;
    }
    cout << sum(vec) << endl;
  }
  return 0;
}
