#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  map<long long, long long> A;
  for (int i = 0; i < N; i++) {
    long long a;
    cin >> a;
    A[a]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    long long b, c;
    cin >> b >> c;
    A[c] += A[b];
    A[b] = 0;
    A.erase(b);
    long long s = 0;
    for (auto it = A.begin(); it != A.end(); it++) {
      s += (*it).first * (*it).second;
    }
    cout << s << endl;
  }
  return 0;
}
