#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  vector<int> a(100009);
  for (int i = (int)(0); i < (int)(n); i++) {
    int in = 0;
    cin >> in;
    a.at(in)++;
  }
  int q = 0;
  cin >> q;
  vector<pair<int, int>> shiji(q);
  for (int i = (int)(0); i < (int)(q); i++) {
    cin >> shiji.at(i).first >> shiji.at(i).second;
  }
  for (int j = (int)(1); j < (int)(q + 1); j++) {
    for (int i = (int)(0); i < (int)(j); i++) {
      a.at(shiji.at(i).second) += a.at(shiji.at(i).first);
      a.at(shiji.at(i).first) = 0;
      long long sum = 0;
      for (int i = (int)(0); i < (int)(100009); i++) {
        sum += (long long)i * a.at(i);
      }
      if (i == j - 1) {
        cout << sum << endl;
      }
    }
  }
}
