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