#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<int, int> p;
  for (int i = 0; i < N; i++) {
    int n;
    cin >> n;
    if (p.count(n))
      p[n] += 1;
    else
      p[n] = 1;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int a, b;
    int sum = 0;
    cin >> a >> b;
    if (p.count(a)) {
      p[b] += p[a];
      p[a] = 0;
    }
    for (auto q : p) {
      auto k = q.first;
      auto v = q.second;
      sum += k * v;
    }
    cout << sum << endl;
  }
  return 0;
}
