#include <bits/stdc++.h>
using namespace std;
const int max_n = 2000;
int grp_siz[max_n], grp_mon[max_n], tbl_siz[max_n];
int id_grp[max_n], id_tbl[max_n];
bool used_tbl[max_n];
bool cmp_grp_mon_desc(int id1, int id2) { return grp_mon[id1] > grp_mon[id2]; }
bool cmp_tbl_siz(int id1, int id2) { return tbl_siz[id1] < tbl_siz[id2]; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int no_orders;
  cin >> no_orders;
  for (int i = 0; i < no_orders; ++i) {
    cin >> grp_siz[i] >> grp_mon[i];
    id_grp[i] = i;
  }
  int no_table;
  cin >> no_table;
  for (int i = 0; i < no_table; ++i) {
    cin >> tbl_siz[i];
    id_tbl[i] = i;
  }
  sort(id_grp, id_grp + no_orders, cmp_grp_mon_desc);
  sort(id_tbl, id_tbl + no_table, cmp_tbl_siz);
  vector<pair<int, int>> ans;
  int total_p = 0;
  for (int i = 0; i < no_orders; ++i) {
    int it = 0;
    while ((it < no_table) &&
           (used_tbl[id_tbl[it]] || tbl_siz[id_tbl[it]] < grp_siz[id_grp[i]]))
      ++it;
    if (it < no_table) {
      used_tbl[id_tbl[it]] = true;
      total_p += grp_mon[id_grp[i]];
      ans.emplace_back(id_grp[i], id_tbl[it]);
    }
  }
  cout << ans.size() << ' ' << total_p << '\n';
  for (auto i : ans) {
    cout << i.first + 1 << ' ' << i.second + 1 << '\n';
  }
}
