#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  map<ll, ll> mp;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    mp[a]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int from, to;
    cin >> from >> to;
    if (mp.count(from) > 0) {
      mp[to] = mp[to] + mp[from];
      mp[from] = 0;
    }
    ll ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
      ans += itr->first * itr->second;
    }
    cout << ans << endl;
  }
  return 0;
}
