#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[500000];
  long long int sum = 0;
  unordered_map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int c, b;
    cin >> c >> b;
    if (m.count(c)) {
      sum = sum - c * (m[c]);
      sum = sum + b * (m[c]);
      auto it = m.find(c);
      if (it != m.end()) {
        auto s = it->second;
        m.insert({b, m[c]});
        m.erase(it);
      }
    }
    cout << sum << endl;
  }
}
