#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> count_A(100000, 0);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    count_A.at(a - 1)++;
  }
  int Q;
  cin >> Q;
  int sum = 0;
  for (int i = 0; i < 100000; i++) {
    sum += count_A.at(i) * (i + 1);
  }
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    sum += (c - b) * count_A.at(b - 1);
    cout << sum << endl;
    count_A.at(c - 1) += count_A.at(b - 1);
    count_A.at(b - 1) = 0;
  }
  return 0;
}
