#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, k, r, sum;
struct zay {
  long long id, c, p;
};
struct stopl {
  long long id, vm;
};
vector<stopl> st;
vector<zay> v;
vector<pair<long long, long long> > res;
bool myf(zay a, zay b) { return a.c > b.c; }
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    zay z;
    z.id = i + 1;
    cin >> z.p >> z.c;
    v.push_back(z);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    stopl sl;
    sl.id = i + 1;
    cin >> sl.vm;
    st.push_back(sl);
  }
  sort(v.begin(), v.end(), myf);
  for (int i = 0; i < n; i++) {
    long long minvm = 1e8, minid = 0, iddel;
    int j = 0;
    for (j = 0; j < st.size(); j++) {
      if (v[i].p <= st[j].vm) {
        if (st[j].vm < minvm) {
          minvm = st[j].vm;
          minid = st[j].id;
          iddel = j;
        }
      }
    }
    if (minid != 0) {
      sum += v[i].c;
      st.erase(st.begin() + iddel);
      res.push_back(make_pair(v[i].id, minid));
    }
  }
  cout << res.size() << " " << sum << "\n";
  for (int i = 0; i < res.size(); i++) {
    cout << res[i].first << " " << res[i].second << "\n";
  }
  return 0;
}
