#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  unordered_map<int, int> mp;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int temp;
    cin >> temp;
    sum += temp;
    auto x = mp.find(temp);
    if (x == mp.end())
      mp[temp] = 1;
    else
      x->second++;
  }
  cin >> Q;
  while (Q--) {
    int B, C;
    cin >> B >> C;
    auto x = mp.find(B);
    if (x != mp.end()) {
      int count = x->second;
      sum = sum - (x->second) * B + (x->second) * C;
      auto y = mp.find(C);
      mp.erase(x);
      if (y == mp.end()) {
        mp.insert(make_pair(C, count));
      } else
        mp[C] += count;
    }
    cout << sum << endl;
  }
}
