#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, ans = 0;
  vector<int> A(N), P(1e5 + 100);
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
    ans += A.at(i);
    ++P.at(A.at(i));
  }
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int b, c;
    cin >> b >> c;
    ans -= b * P.at(b);
    ans += c * P.at(b);
    P.at(c) += P.at(b);
    P.at(b) = 0;
    cout << ans << endl;
  }
  return 0;
}
