#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  unordered_multiset<int> a;
  int cumsum = 0;
  for (int i = 0; i < n; ++i) {
    int ai;
    cin >> ai;
    a.insert(ai);
    cumsum += ai;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    int cnt = a.count(b);
    cumsum -= cnt * b;
    cumsum += cnt * c;
    cout << cumsum << "\n";
    a.erase(b);
    for (int j = 0; j < cnt; ++j) a.insert(c);
  }
}
