#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  long long sum = 0;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int u, v;
    cin >> u >> v;
    if (m.find(u) != m.end()) {
      sum -= (u * m[u]);
      sum += (v * m[u]);
      m[v] += m[u];
      m.erase(u);
    }
    cout << sum << "\n";
  }
  return 0;
}
