#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int q;
  cin >> q;
  int b[n], c[n];
  for (int i = 0; i < (q); ++i) cin >> b[i] >> c[i];
  map<int, int> count;
  for (int i = 0; i < (n); ++i) count[a[i]]++;
  long long sum = 0;
  for (auto v : count) sum += (long long)v.first * v.second;
  for (int i = 0; i < (q); ++i) {
    if (count[b[i]] != 0) {
      int tmp = count[b[i]];
      count[c[i]] += tmp;
      count[b[i]] = 0;
      sum += (long long)(c[i] - b[i]) * tmp;
    }
    cout << sum << endl;
  }
  return 0;
}
