#include <bits/stdc++.h>
using namespace std;
int total[10001], N, Q, sum;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    sum += a;
    total[a]++;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    sum -= B * total[B];
    sum += C * total[B];
    total[C] += total[B];
    total[B] = 0;
    cout << sum << "\n";
  }
}
