#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  int A;
  map<int, int> numbers;
  for (int i = 0; i < N; i++) {
    cin >> A;
    numbers[A]++;
  }
  long long ans = 0;
  for (auto elem : numbers) {
    ans += elem.first * elem.second;
  }
  cin >> Q;
  int B, C;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    int n = numbers[B];
    if (n != 0) {
      numbers[C] += n;
      numbers.erase(B);
      ans -= B * n;
      ans += C * n;
    }
    cout << ans << endl;
  }
}
