#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, val, sum = 0;
  cin >> N;
  multiset<long long> ival;
  for (int i = 0; i < N; i++) {
    cin >> val;
    ival.insert(val);
    sum += val;
  }
  long long Q, b, c;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> b;
    cin >> c;
    if (ival.find(b) != ival.end()) {
      int count = ival.count(b);
      ival.erase(b);
      for (int i = 0; i < count; i++) {
        ival.insert(c);
      }
      sum = sum - count * b + count * c;
    }
    cout << sum << '\n';
  }
}
