#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<long long> a(n);
  map<long long, long long> mp_a;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp_a[a[i]]++;
  }
  long long q;
  cin >> q;
  vector<long long> b(q), c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (long long i = 0; i < q; i++) {
    mp_a[c[i]] += mp_a[b[i]];
    mp_a[b[i]] = 0;
    long long ans = 0;
    for (auto itr = mp_a.begin(); itr != mp_a.end(); ++itr) {
      ans += itr->first * itr->second;
    }
    cout << ans << endl;
  }
}
