#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, q, s = 0;
  cin >> n;
  long long x[100002], y[100002] = {0}, i;
  for (i = 1; i <= n; i++) {
    cin >> x[i];
    y[x[i]]++;
  }
  cin >> q;
  while (q--) {
    long long b, c, ans = 0;
    cin >> b >> c;
    y[c] += y[b];
    y[b] -= y[b];
    for (i = 1; i < 100002; i++) {
      ans += (i * y[i]);
    }
    cout << ans << "\n";
  }
  return 0;
}
