#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  std::unordered_map<int, int> m;
  long long sum = 0;
  for (int i = 0; i < (N); ++i) {
    cin >> A[i];
    sum += A[i];
    m[A[i]]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < (Q); ++i) {
    int B, C;
    cin >> B >> C;
    sum -= B * m[B];
    sum += C * m[B];
    cout << sum << endl;
    m[C] += m[B];
  }
  return 0;
}
