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