#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long sum = 0;
  vector<long long> v(n);
  map<long long, long long> make_pair;
  for (long long i = 0; i <= n - 1; ++i) {
    cin >> v[i];
    make_pair[v[i]]++;
    sum += v[i];
  }
  long long q;
  cin >> q;
  while (q--) {
    long long a, b;
    cin >> a >> b;
    sum -= make_pair[a] * a;
    make_pair[b] += make_pair[a];
    sum += make_pair[a] * b;
    cout << sum << "\n";
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
