#include <bits/stdc++.h>
using namespace std;
int get_sum(map<int, int> counter) {
  int s = 0;
  for (map<int, int>::iterator it = counter.begin(); it != counter.end();
       ++it) {
    s += it->first * it->second;
  }
  return s;
}
int main() {
  int N;
  int A;
  map<int, int> counter;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A;
    counter[A]++;
  }
  int s = get_sum(counter);
  int Q;
  cin >> Q;
  int B, C;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    counter[C] += counter[B];
    counter[B] = 0;
    cout << get_sum(counter) << endl;
  }
}
