#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  vector<int> freq(100000, 0);
  long sum = 0L;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    freq[a - 1]++;
    sum += a;
  }
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> B[i];
    cin >> C[i];
  }
  for (int i = 0; i < Q; ++i) {
    sum -= B[i] * freq[B[i] - 1];
    sum += C[i] * freq[B[i] - 1];
    freq[C[i] - 1] += freq[B[i] - 1];
    freq[B[i] - 1] = 0;
    cout << sum << endl;
  }
  return 0;
}
