#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, q;
  cin >> n;
  ll ans = 0;
  vector<ll> cnt(11000, 0);
  for (ll i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    ans += tmp;
    cnt[tmp]++;
  }
  cin >> q;
  for (ll i = 0; i < q; i++) {
    ll x, y;
    cin >> x >> y;
    ans += (y - x) * cnt[x];
    cnt[y] += cnt[x];
    cnt[x] = 0;
    cout << ans << endl;
  }
}
