#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<long long> a(n);
  map<long long, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  int q;
  cin >> q;
  for (int qq = 0; qq < q; qq++) {
    long long b, c;
    cin >> b >> c;
    mp[c] += mp[b];
    mp[b] = 0;
    long long sum = 0;
    for (auto p : mp) {
      sum += p.first * p.second;
    }
    cout << sum << endl;
  }
  return 0;
}
