#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> bunpu(100000);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += a;
    bunpu.at(a - 1)++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int diff = c - b;
    sum += diff * bunpu.at(b - 1);
    bunpu.at(c - 1) += bunpu.at(b - 1);
    bunpu.at(b - 1) = 0;
    cout << sum << endl;
  }
  return 0;
}
