#include <bits/stdc++.h>
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (ll i = 0; i < n; i++) {
    int a;
    cin >> a;
    mp[a]++;
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (ll i = 0; i < q; i++) cin >> b[i] >> c[i];
  for (ll i = 0; i < q; i++) {
    mp[c[i]] += mp[b[i]];
    mp[b[i]] = 0;
    ll ans = 0;
    for (auto x : mp) ans += x.first * x.second;
    cout << ans << "\n";
  }
  return 0;
}
