#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  vector<int> bucket(100000, 0);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    bucket.at(x - 1)++;
    sum += x;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    sum += (c - b) * bucket.at(b - 1);
    bucket.at(c - 1) += bucket.at(b - 1);
    bucket.at(b - 1) = 0;
    cout << sum << endl;
  }
}
