#include <bits/stdc++.h>
using namespace std;
void Main() {
  long long N;
  cin >> N;
  map<long long, long long> A;
  for (long long i = 0; i < N; ++i) {
    long long a;
    cin >> a;
    if (A.count(a) == 0) {
      A.insert(make_pair(a, 0));
    }
    A[a] += 1;
  }
  long long Q;
  cin >> Q;
  for (long long i = 0; i < Q; ++i) {
    long long b, c;
    cin >> b >> c;
    if (A.count(b) > 0) {
      if (A.count(c) == 0) {
        A.insert(make_pair(c, 0));
      }
      A[c] += A[b];
      A.erase(b);
    }
    long long ans = 0;
    for (auto e : A) {
      ans += e.first * e.second;
    }
    cout << ans << endl;
  }
}
int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
