#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  multiset<int> A;
  int t1;
  cin >> N;
  for (int i = 0; i != N; i++) {
    cin >> t1;
    A.insert(t1);
  }
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i != Q; i++) {
    cin >> B[i];
    cin >> C[i];
  }
  long initSum = 0;
  for (auto it = A.begin(); it != A.end(); it++) initSum += *it;
  long out = initSum;
  for (int i = 0; i != Q; i++) {
    auto beg = A.lower_bound(B[i]);
    auto end = A.upper_bound(B[i]);
    int n = distance(beg, end);
    out = (out + n * (C[i] - B[i]));
    A.erase(beg, end);
    for (int j = 0; j != n; j++) A.insert(C[i]);
    cout << out << " " << n << " ";
    for (auto it = A.begin(); it != A.end(); it++) cout << *it << ",";
    cout << endl;
  }
  return 0;
}
