#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  unordered_map<int, int> map;
  int64_t count = 0;
  for (int i = 0; i < N; ++i) {
    int A;
    cin >> A;
    ++map[A];
    count += A;
  }
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int B, C;
    cin >> B >> C;
    count -= map[B] * B;
    map[C] += map[B];
    map.erase(B);
    count += map[C] * C;
    cout << count << endl;
  }
  return 0;
}
