#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  vector<int> A(N);
  int sum = 0;
  map<int, int> occur;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
    occur[A[i]]++;
  }
  int Q, B, C;
  cin >> Q;
  while (Q--) {
    cin >> B >> C;
    sum += (C - B) * occur[B];
    cout << sum << endl;
    occur[C] += occur[B];
    occur[B] = 0;
  }
  return 0;
}
