#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> B.at(i) >> C.at(i);
  }
  vector<int> count(10 * 10 * 10 * 10 * 10 + 1, 0);
  for (int i = 0; i < A.size(); ++i) {
    ++count.at(A.at(i));
  }
  int sum = accumulate(A.begin(), A.end(), 0);
  for (int i = 0; i < Q; ++i) {
    sum += C.at(i) * count.at(B.at(i)) - B.at(i) * count.at(B.at(i));
    count.at(C.at(i)) += count.at(B.at(i));
    count.at(B.at(i)) = 0;
    cout << sum << endl;
  }
}
