#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <typename T1, typename T2>
using P = pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<LL, LL>;
using Pdd = P<double, double>;
using Psi = P<string, double>;
template <typename T>
using V = vector<T>;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;
int main() {
  LL N;
  cin >> N;
  Vll A(N);
  for (int i = 0; i < (N); i++) cin >> A[i];
  LL Q;
  cin >> Q;
  Vll B(Q), C(Q);
  for (int i = 0; i < (Q); i++) cin >> B[i] >> C[i];
  Vll num_A(100005);
  LL total_A = 0;
  for (int i = 0; i < (N); i++) {
    num_A[A[i]]++;
    total_A += A[i];
  }
  cout << total_A << endl;
  for (int i = 0; i < (Q); i++) {
    total_A -= B[i] * num_A[B[i]];
    total_A += C[i] * num_A[B[i]];
    cout << total_A << endl;
    num_A[C[i]] += num_A[B[i]];
    num_A[B[i]] -= num_A[B[i]];
  }
  return 0;
}
