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