#include <bits/stdc++.h>
int main() {
  int n, *a;
  std::cin >> n;
  a = new int[n];
  std::unordered_map<int, int> countmap;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    countmap[a[i]]++;
    sum += a[i];
  }
  int q, s, r;
  std::cin >> q;
  while (q--) {
    std::cin >> s >> r;
    sum -= (s * countmap[s]);
    sum += (r * countmap[s]);
    countmap[r] += countmap[s];
    countmap[s] = 0;
    std::cout << sum << std::endl;
  }
  delete[] a;
}
