#include <bits/stdc++.h>
using namespace std;
pair<pair<int, int>, int> v[20010];
int main() {
  ios_base::sync_with_stdio(false);
  int n, ans = 0, no = 0, kx = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c, p;
    cin >> c >> p;
    v[i] = make_pair(make_pair(p, c), i + 1);
  }
  sort(v, v + n);
  reverse(v, v + n);
  int k;
  cin >> k;
  pair<int, int> t[20010];
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    t[i] = make_pair(x, i + 1);
  }
  sort(t, t + k);
  pair<int, int> px[20010];
  bool mark[20010];
  memset(mark, false, sizeof(mark));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (v[i].first.second <= t[j].first && !mark[j]) {
        mark[j] = true;
        ans += v[i].first.first;
        no++;
        px[kx++] = make_pair(v[i].second, t[j].second);
        break;
      }
    }
  }
  cout << no << " " << ans << endl;
  for (int i = 0; i < kx; i++) {
    cout << px[i].first << " " << px[i].second << endl;
  }
  return 0;
}
