#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<int, int> A;
  int a;
  for (int i = 0; i < N; i++) {
    cin >> a;
    if (A.count(a)) {
      A[a]++;
    } else {
      A[a] = 1;
    }
  }
  int Q;
  cin >> Q;
  vector<long long> S(Q);
  int b, c;
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    if (A.count(b)) {
      if (A.count(c)) {
        A[c] += A[b];
      } else {
        A[c] = A[b];
      }
    }
    A.erase(b);
    long long s = 0;
    for (pair<int, int> kv : A) {
      s += kv.first * kv.second;
    }
    S.at(i) = s;
  }
  for (int i = 0; i < Q; i++) {
    cout << S.at(i) << endl;
  }
  return 0;
}
