#include <bits/stdc++.h>
using namespace std;
bool gp(pair<int, int> &p1, pair<int, int> &p2) {
  return (p1.first < p2.first);
}
bool gi(vector<int> &v1, vector<int> &v2) { return (v1[0] < v2[0]); }
int main() {
  int n, m, res[1002][1002]{}, x, y;
  cin >> n;
  vector<vector<int>> items(n + 1);
  for (int i = 0; i < 3; ++i) items[0].push_back(0);
  for (int i = 1; i <= n; ++i) {
    cin >> x >> y;
    items[i].push_back(x);
    items[i].push_back(y);
    items[i].push_back(i);
  }
  cin >> m;
  vector<pair<int, int>> place(m + 1);
  place[0].first = 0;
  place[0].second = 0;
  for (int i = 1; i <= m; ++i) {
    cin >> x;
    place[i].first = x;
    place[i].second = i;
  }
  sort(place.begin(), place.end(), gp);
  sort(items.begin(), items.end(), gi);
  for (int i = 1; i <= m; ++i)
    place[i].first = place[i - 1].first + place[i].first;
  vector<pair<int, int>> sum;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (items[i][0] <= place[j].first - place[j - 1].first) {
        res[i][j] = max(res[i - 1][j], items[i][1] + res[i - 1][j - 1]);
      } else
        res[i][j] = res[i - 1][j];
    }
  }
  x = n, y = m;
  while (x > 0 && y > 0) {
    if (res[x][y] != res[x - 1][y]) {
      sum.push_back(make_pair(items[x][2], place[y].second));
      y--;
    }
    x--;
  }
  cout << sum.size() << ' ' << res[n][m] << endl;
  for (int i = 0; i < sum.size(); ++i)
    cout << sum[i].first << ' ' << sum[i].second << endl;
  return 0;
}
