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