#include <bits/stdc++.h>
using namespace std;
signed main() {
  int N;
  cin >> N;
  unsigned long long int count = 0;
  vector<unsigned long long int> A(N + 1);
  vector<int> D(100001);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    count += A[i];
    D[A[i]]++;
  }
  int Q;
  cin >> Q;
  vector<int> B(Q + 1);
  vector<int> C(Q + 1);
  for (int i = 1; i <= Q; i++) {
    cin >> B[i] >> C[i];
    count += D[B[i]] * (C[i] - B[i]);
    cout << count << endl;
    D[C[i]] += D[B[i]];
  }
}
