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