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