#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ;
  ll n = 0;
  cin >> n;
  ll ar[n];
  for (ll i = 0; i < n; ++i) cin >> ar[i];
  map<ll, ll> freq;
  for (ll i = 0; i < n; ++i) ++freq[ar[i]];
  ll sum = accumulate(ar, ar + n, 0);
  ll q = 0;
  cin >> q;
  while (q--) {
    ll u = 0, v = 0;
    cin >> u >> v;
    ll c = freq[u];
    freq[u] = 0;
    freq[v] += c;
    sum -= u * c;
    sum += v * c;
    cout << sum << "\n";
  }
  return 0;
}
