#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
int main() {
  ll N;
  cin >> N;
  vl A(N);
  map<ll, ll> a;
  for (ll i = 0; i < N; i++) {
    cin >> A.at(i);
    a[A.at(i)] += 1;
  }
  ll Q;
  cin >> Q;
  ll b, c;
  ll tmp;
  for (ll i = 0; i < Q; i++) {
    ll sum = 0;
    cin >> b >> c;
    if (a.find(b) != a.end()) {
      tmp = a.at(b);
      a.at(b) = 0;
      a[c] += tmp;
    }
    for (auto c : a) {
      sum += c.first * c.second;
    }
    cout << sum << endl;
  }
}
