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