#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
int main() {
  int n;
  cin >> n;
  vector<long long> x(100010);
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    x[a]++;
  }
  int q;
  cin >> q;
  int b[q + 1], c[q + 1];
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int j = 0; j < q; j++) {
    unsigned long long ans = 0;
    for (int i = 1; i <= MAX; i++) {
      if (b[j] == i) {
        x[c[j]] += x[b[j]];
        x[b[j]] = 0;
      }
    }
    for (int i = 1; i <= MAX; i++) {
      ans += x[i] * i;
    }
    cout << ans << endl;
  }
  return 0;
}
