#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(100010);
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[a]++;
    sum += a;
  }
  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++) {
    sum -= B[i] * A[B[i]];
    sum -= C[i] * A[C[i]];
    A[C[i]] += A[B[i]];
    A[B[i]] = 0;
    sum += C[i] * A[C[i]];
    cout << sum << endl;
  }
  return 0;
}
