#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
int main() {
  ll N;
  cin >> N;
  multiset<ll> ms;
  ll sum = 0;
  for (int i = 0; i < (int)(N); i++) {
    ll tmp;
    cin >> tmp;
    ms.insert(tmp);
    sum += tmp;
  }
  ll Q;
  cin >> Q;
  for (int i = 0; i < (int)(Q); i++) {
    ll B, C;
    cin >> B >> C;
    ll cnt = ms.erase(B);
    for (int j = 0; j < (int)(cnt); j++) {
      ms.insert(C);
    }
    sum += (C - B) * cnt;
    cout << sum << endl;
  }
  return 0;
}
