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