#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr double PI = 3.141592653589793238462643383279;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
int main() {
  ll n;
  cin >> n;
  multimap<int, int> m;
  for (int i = 0; i < (n); ++i) {
    int tmp;
    cin >> tmp;
    m.insert(make_pair(tmp, i));
  }
  ll q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    ll b, c;
    cin >> b >> c;
    auto itr = m.find(b);
    for (int j = 0; j < m.count(b); j++) {
      int ret = m.erase(b);
      for (int k = 0; k < (ret); ++k) {
        m.insert(make_pair(c, 1));
      }
      itr++;
    }
    ll sum = 0;
    for (auto it = m.begin(); it != m.end(); it++) {
      sum += it->first;
    }
    cout << sum << endl;
  }
}
