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