#include <bits/stdc++.h>
using namespace std;
long sum(vector<long> a) {
  long sum = 0;
  for (int i = 0; i < a.size(); i++) {
    sum += a[i] * i;
  }
  return sum;
}
int main() {
  long n, q, b, c, temp;
  vector<long> a(100001);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    a[temp]++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    a[c] += a[b];
    a[b] = 0;
    cout << sum(a) << endl;
  }
  return 0;
}
