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