#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  map<int64_t, int64_t> m;
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
    m[A[i]] = m[A[i]] + 1;
  }
  int64_t Q;
  cin >> Q;
  vector<int64_t> B(Q), C(Q);
  for (int64_t i = 0; i < Q; ++i) {
    cin >> B[i] >> C[i];
    int64_t num = m[B[i]];
    m[B[i]] = 0;
    m[C[i]] = m[C[i]] + num;
    int64_t sum = 0;
    for (auto p : m) {
      int64_t val = p.first;
      int64_t num = p.second;
      sum = sum + val * num;
    }
    cout << sum << endl;
  }
  return 0;
}
