#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::unordered_map<int, int> numArray;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    std::cin >> a;
    ++numArray[a];
    sum += a;
  }
  int q;
  std::cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    std::cin >> b >> c;
    if (numArray.find(b) != numArray.end()) {
      int const changeNum = numArray.at(b);
      numArray[c] += changeNum;
      sum += (c - b) * changeNum;
    }
    std::cout << sum << std::endl;
  }
}
