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