#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<int, int> A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (A.count(a)) {
      A.at(a)++;
    } else {
      A[a] = 1;
    }
  }
  int Q;
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B.at(i) >> C.at(i);
  }
  for (int i = 0; i < Q; i++) {
    if (A.count(B.at(i))) {
      int a_2 = A[B.at(i)];
      int a_1 = B.at(i);
      A.erase(a_1);
      int new_a_1 = C.at(i);
      if (A.count(new_a_1)) {
        A[new_a_1] += a_2;
      } else {
        A[new_a_1] = a_2;
      }
    }
    int sum = 0;
    for (pair<int, int> p : A) {
      sum += p.first * p.second;
    }
    cout << sum << "\n";
  }
}
