#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  map<int, int> A;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    A[tmp]++;
  }
  int Q;
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < Q; i++) {
    int a = A[B[i]];
    A.erase(B[i]);
    A[C[i]] += a;
    ll output = 0;
    for (auto x : A) {
      output += x.first * x.second;
    }
    cout << output << endl;
  }
  return 0;
}
