#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, b, c;
  map<int, int> m;
  cin >> n;
  unsigned long long sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    m[x]++;
    sum += x;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    if (!m[b])
      cout << sum << "\n";
    else {
      sum = (sum - (b * m[b]) - (c * m[c]));
      m[c] += m[b];
      sum = (sum + (c * m[c]));
      m[b] = 0;
      cout << sum << "\n";
    }
  }
  return 0;
}
