#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  long sum = 0;
  std::vector<int> abox(100000);
  for (int i = 0; i < n; ++i) {
    int v;
    std::cin >> v;
    sum += v;
    ++abox[v];
  }
  int q;
  std::cin >> q;
  std::vector<std::pair<int, int>> bc(q);
  for (int i = 0; i < q; ++i) {
    std::cin >> bc[i].first;
    std::cin >> bc[i].second;
  }
  std::vector<long> s(q);
  for (int i = 0; i < q; ++i) {
    int delta = abox[bc[i].first];
    abox[bc[i].first] = 0;
    abox[bc[i].second] += delta;
    sum -= delta * bc[i].first;
    sum += delta * bc[i].second;
    std::cout << sum << std::endl;
  }
}
