#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using lli = long long int;
using ull = unsigned long long;
int main() {
  ull N, Q, A_i, B_i, C_i, temp, sum = 0;
  vector<ull> A_num(100001, 0);
  cin >> N;
  for (ull i = 0; i < N; i++) {
    cin >> temp;
    A_num.at(temp) += 1;
    sum += temp;
  }
  cin >> Q;
  for (ull i = 0; i < Q; i++) {
    cin >> B_i >> C_i;
    if (A_num[B_i] != 0) {
      sum += A_num[B_i] * (C_i - B_i);
      A_num[C_i] += A_num[B_i];
      A_num[B_i] = 0;
      cout << sum << endl;
    }
  }
  return 0;
}
