#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(void) {
  ll n;
  cin >> n;
  vector<ll> a(n, 0);
  for (ll i = 0; i < n; ++i) cin >> a[i];
  ll q;
  cin >> q;
  vector<ll> b(n, 0);
  vector<ll> c(n, 0);
  for (ll i = 0; i < q; ++i) cin >> b[i] >> c[i];
  map<ll, ll> m;
  for (ll i = 0; i < n; ++i) ++m[a[i]];
  ll res = 0;
  for (ll i = 0; i < n; ++i) res += a[i];
  for (ll i = 0; i < q; ++i) {
    res += m[b[i]] * (c[i] - b[i]);
    cout << res << endl;
    ll t = m[b[i]];
    m[b[i]] = 0;
    m[c[i]] += t;
  }
}
int main(void) {
  solve();
  return 0;
}
