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