#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, q, take;
  long sum = 0;
  cin >> n;
  unordered_multiset<long> a;
  for (long i = 0; i < n; i++) {
    cin >> take;
    a.insert(take);
    sum += take;
  }
  cin >> q;
  long b, c;
  for (long i = 0; i < q; i++) {
    cin >> b >> c;
    long d = b - c;
    long f = a.count(b);
    a.erase(b);
    for (long i = 0; i < f; i++) a.insert(c);
    sum -= d * f;
    cout << sum << endl;
  }
}
