#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INFint = 1e9 + 1;
const ll INFll = (ll)1e18 + 1;
ll MOD = 1e9 + 7;
int main() {
  int N;
  cin >> N;
  map<ll, ll> m;
  vector<int> A(N);
  for (int i(0); i < N; i++) {
    cin >> A[i];
    m[A[i]]++;
  }
  ll ans(0);
  for (auto mi : m) {
    ans += mi.first * mi.second;
  }
  int Q;
  cin >> Q;
  for (int i(0); i < Q; i++) {
    int b, c;
    cin >> b >> c;
    int tmp = m[b];
    m[c] += tmp;
    ans -= (b - c) * tmp;
    cout << ans << endl;
  }
  return 0;
}
