#include <bits/stdc++.h>
using namespace std;
struct req {
  int people;
  int money;
  int rnum;
} r[1005];
struct hmm {
  int number;
  int capa;
} table[1005];
bool operator<(hmm a, hmm b) { return a.capa < b.capa; }
bool operator<(req a, req b) {
  if (a.money > b.money)
    return true;
  else if (a.money == b.money && a.people < b.people)
    return true;
  return false;
}
multiset<hmm> tablecap;
int finalans[1005][2];
int idx = 0;
int main(void) {
  std::ios::sync_with_stdio(false);
  tablecap.clear();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i].people;
    cin >> r[i].money;
    r[i].rnum = i + 1;
  }
  int ta;
  cin >> ta;
  for (int i = 0; i < ta; i++) {
    cin >> table[i].capa;
    table[i].number = i + 1;
    tablecap.insert(table[i]);
  }
  int accepted = 0, profit = 0;
  sort(r, r + n);
  multiset<hmm>::iterator it1, it2;
  for (int i = 0; i < n; i++) {
    it1 = tablecap.upper_bound((hmm){1, r[i].people - 1});
    if (it1 != tablecap.end()) {
      accepted++;
      profit += r[i].money;
      finalans[idx][0] = r[i].rnum;
      finalans[idx][1] = (*it1).number;
      idx++;
      tablecap.erase(it1);
    }
  }
  cout << accepted << " " << profit << endl;
  for (int i = 0; i < idx; i++) {
    cout << finalans[i][0] << " " << finalans[i][1] << endl;
  }
  return 0;
}
