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