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