#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  vector<int> A(N);
  vector<int> dp(100001);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  cin >> Q;
  auto sum_ll = accumulate(A.begin(), A.end(), 0LL);
  size_t n_count_B;
  size_t n_count_C;
  for (int i = 1; i < 100001; i++) {
    dp.at(i) = count(A.begin(), A.end(), i);
  }
  int B, C;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    n_count_B = dp.at(B);
    n_count_C = dp.at(C);
    sum_ll = sum_ll + C * n_count_B - B * n_count_B;
    dp.at(B) = 0;
    dp.at(C) = n_count_C + n_count_B;
    cout << sum_ll << endl;
  }
  return 0;
}
