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