#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  unordered_map<int, int> hashmap;
  int A;
  for (int i = 0; i < N; i++) {
    cin >> A;
    hashmap[A]++;
  }
  int Q;
  cin >> Q;
  int B, C;
  long ans;
  int tmp;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    ans = 0;
    auto itr = hashmap.find(B);
    if (itr != hashmap.end()) {
      tmp = hashmap[B];
      auto itr2 = hashmap.find(C);
      if (itr != hashmap.end()) {
        hashmap[C] = hashmap[C] + tmp;
      } else {
        hashmap[C]++;
      }
      hashmap.erase(itr);
    }
    for (pair<int, int> p : hashmap) {
      ans = p.first * p.second + ans;
    }
    cout << ans << endl;
  }
}
