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