#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<int> cnt(100001, 0);
  for (int i = 0; i < N; i++) cnt.at(A.at(i))++;
  long long S = 0;
  for (int i = 0; i < N; i++) S += 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);
  for (int i = 0; i < Q; i++) {
    int b = B.at(i);
    int c = C.at(i);
    S -= b * cnt.at(b);
    S += c * cnt.at(b);
    cnt.at(c) += cnt.at(b);
    cnt.at(b) = 0;
    cout << S << endl;
  }
}
