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