#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 < (int)N; i++) {
    int a;
    cin >> a;
    A[a]++;
  }
  int Q;
  cin >> Q;
  while (Q--) {
    ans = 0;
    int b, c;
    cin >> b >> c;
    int Ab = A[b];
    int Ac = A[c];
    A[c] += Ab;
    A[b] = 0;
    for (auto p : A) {
      ans += p.first * p.second;
    }
    cout << ans << endl;
  }
}
