#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, q;
  cin >> n;
  unordered_map<int, int> a;
  ll current = 0;
  for (int i = 0; i < (int)n; i++) {
    int temp;
    cin >> temp;
    a[temp]++;
    current += temp;
  }
  cin >> q;
  for (int i = 0; i < (int)q; i++) {
    int b, c;
    cin >> b >> c;
    if (a.count(b)) {
      int kosu = a.at(b);
      int erased = b * kosu;
      current -= erased;
      int inserted = c * kosu;
      current += inserted;
      a.erase(b);
      a[c] += kosu;
    }
    cout << current << endl;
  }
  return 0;
}
