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