#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  vector<int> vect(100000, 0);
  int sum = 0;
  int temp = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    sum = sum + temp;
    vect[temp]++;
  }
  int q = 0;
  cin >> q;
  int t1 = 0;
  int t2 = 0;
  for (int i = 0; i < q; i++) {
    cin >> t1 >> t2;
    if (vect[t1] != 0) {
      vect[t2] = vect[t2] + vect[t1];
      sum = sum - (t1 * vect[t1]) + (t2 * vect[t1]);
      cout << sum << endl;
      vect[t1] = 0;
    } else {
      cout << sum << endl;
    }
  }
  return 0;
}
