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