#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(100001);
  int a = 0;
  long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a;
    A.at(a)++;
    sum += a;
  }
  int Q;
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B.at(i) >> C.at(i);
  }
  int b = 0;
  for (int i = 0; i < Q; i++) {
    b = A.at(B.at(i));
    A.at(B.at(i)) = 0;
    A.at(C.at(i)) += b;
    sum = sum - B.at(i) * b + C.at(i) * b;
    cout << sum << endl;
  }
  return 0;
}
