#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> m;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (!m.count(A.at(i))) {
      m[A.at(i)] = 1;
    } else {
      m[A.at(i)]++;
    }
  }
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B.at(i) >> C.at(i);
  }
  long long num;
  for (int i = 0; i < Q; i++) {
    if (m.count(B.at(i))) {
      if (!m.count(C.at(i))) {
        m[C.at(i)] = 0;
      }
      m[C.at(i)] += m[B.at(i)];
      m.erase(B.at(i));
    }
    num = 0;
    for (pair<int, int> p : m) {
      num += p.first * p.second;
    }
    cout << num << endl;
  }
}
