#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N;
  cin >> N;
  map<ll, ll> A;
  for (ll i = 0; i < N; i++) {
    ll sub;
    cin >> sub;
    A[sub] = ++A[sub];
  }
  ll Q;
  cin >> Q;
  while (Q) {
    ll B, C;
    cin >> B >> C;
    A[C] += A.at(B);
    A.erase(B);
    ll ans = 0;
    for (pair<ll, ll> i : A) {
      ans += i.first * i.second;
    }
    cout << ans << endl;
    Q--;
  }
}
