#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  map<ll, ll> mp;
  ll a[n];
  for (int i = 0; i < n; i++) {
    ll a;
    cin >> a;
    mp[a]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    mp[c] += mp[b];
    mp.erase(b);
    ll ans = 0LL;
    for (auto x : mp) {
      ans += x.first * x.second;
    }
    cout << ans << endl;
  }
  return 0;
}
