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