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