#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  int a, b, c, q;
  ll sum;
  map<int, ll> mp;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    mp[a]++;
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    sum = 0;
    cin >> b >> c;
    auto itr1 = mp.find(b);
    auto itr2 = mp.find(c);
    if (itr1 != mp.end()) {
      if (itr2 == mp.end())
        mp[c] = itr1->second;
      else
        mp[itr2->first] += itr1->second;
      mp[itr1->first] = 0;
    }
    for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
      sum += (itr->first) * (itr->second);
    }
    cout << sum << endl;
  }
  return 0;
}
