#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unordered_multiset<int> mst;
  int suma = 0;
  for (int i = 0; i < n; i++) {
    int cur;
    cin >> cur;
    mst.insert(cur);
    suma += cur;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int antes_b = mst.count(b);
    mst.erase(b);
    for (int i = 0; i < antes_b; i++) mst.insert(c);
    suma -= antes_b * b;
    suma += antes_b * c;
    cout << suma << '\n';
  }
}
