#include <bits/stdc++.h>
int main() {
  int n, q, temp;
  long long sum = 0;
  std::cin >> n;
  std::vector<int> a(1e5 + 1, 0);
  for (int i = 0; i < n; i++) {
    std::cin >> temp;
    a.at(temp)++;
    sum += temp;
  }
  std::cin >> q;
  std::vector<int> b(q), c(q);
  for (int i = 0; i < q; i++) {
    std::cin >> b[i] >> c[i];
  }
  for (int j = 0; j < q; j++) {
    sum -= b[j] * a.at(b[j]);
    sum += c[j] * a.at(b[j]);
    a.at(c[j]) += a.at(b[j]);
    a.at(b[j]) = 0;
    std::cout << sum << std::endl;
  }
  return 0;
}
