#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using namespace std;
int main(void) {
  ll N, Q;
  cin >> N;
  ll a[N];
  map<ll, ll> s;
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    s[a[i]]++;
    ans += a[i];
  }
  cin >> Q;
  ll b[Q], c[Q];
  for (int j = 0; j < Q; ++j) {
    cin >> b[j] >> c[j];
  }
  for (int j = 0; j < Q; ++j) {
    ans += (c[j] - b[j]) * s[b[j]];
    s[c[j]] += s[b[j]];
    b[j] = 0;
    cout << ans << endl;
  }
  return 0;
}
