#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  ll q;
  cin >> q;
  ll total = accumulate((a).begin(), (a).end(), 0);
  map<ll, ll> Counter;
  for (int i = 0; i < (int)(n); i++) {
    Counter[a[i]]++;
  }
  vector<ll> ans(q);
  for (int i = 0; i < (int)(q); i++) {
    ll b, c;
    cin >> b >> c;
    total -= b * Counter[b];
    total += c * Counter[b];
    Counter[c] += Counter[b];
    Counter[b] = 0;
    ans[i] = total;
  }
  for (ll i : ans) {
    cout << i << endl;
  }
}
