#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, q, tmp, k;
  cin >> n;
  vector<long long> A(n);
  for (long long i = 0; i < n; i++) cin >> A[i];
  ;
  cin >> q;
  map<long long, long long> mp;
  set<long long> st;
  for (auto i : A) {
    mp[i]++;
    st.insert(i);
  }
  for (int i = 0; i < q; i++) {
    cin >> tmp >> k;
    if (st.find(tmp) != st.end()) {
      mp[k] += mp[tmp];
      mp[tmp] = 0;
      st.insert(k);
      st.erase(tmp);
    }
    long long sum = 0;
    for (auto j : st) {
      sum += mp[j] * j;
    }
    cout << sum << '\n';
  }
  return 0;
}
