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