#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, q;
  cin >> n;
  vector<int> a(n + 5);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  int d[100005];
  for (int i = 1; i <= 100000; i++) {
    d[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    d[a[i]] += 1;
  }
  for (int i = 0; i < q; i++) {
    long long p = 0;
    int b, c;
    cin >> b >> c;
    d[c] += d[b];
    d[b] = 0;
    for (int i = 1; i <= 100000; i++) {
      p += d[i] * i;
    }
    cout << p << endl;
  }
  return 0;
}
