#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> list(100010, 0);
  vector<int> num(100010, 0);
  int p;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> p;
    sum += p;
    list.at(p)++;
  }
  int Q;
  cin >> Q;
  int B, C;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    sum = sum + (C - B) * list.at(B);
    cout << sum << endl;
    list.at(C) += list.at(B);
    list.at(B) = 0;
  }
}
