#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int n, s = 0, q, a, b;
  cin >> n;
  long long int ar[100001] = {0};
  for (long long int i = 0; i < n; i++) {
    cin >> a;
    ar[a]++;
    s = s + a;
  }
  cin >> q;
  while (q--) {
    cin >> a >> b;
    long long int f = ar[a];
    s = s - (f * a);
    ar[b] = ar[b] + f;
    s = s + (f * b);
    cout << s << "\n";
  }
}
