#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  map<ll, ll> mp;
  ll ans = 0;
  for (int i = (0); i < (N); i++) {
    ll a;
    cin >> a;
    mp[a]++;
    ans += a;
  }
  int Q;
  cin >> Q;
  for (int i = (0); i < (Q); i++) {
    ll b, c;
    cin >> b >> c;
    ll cnt = mp[b];
    ans -= cnt * b;
    mp[c] += cnt;
    ans += c * cnt;
    cout << ans << '\n';
  }
  return 0;
}
