#include <bits/stdc++.h>
using namespace std;
int n, k;
int c[1010], p[1010];
pair<pair<int, int>, int> req[1010];
int r[1010];
int used[1010];
int sum = 0, accept = 0;
bool comp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first != b.first)
    return a.first > b.first;
  else
    return a.first < b.first;
}
int main() {
  memset(used, -1, sizeof(used));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> c[i] >> p[i];
    req[i] = make_pair(make_pair(p[i], c[i]), i);
  }
  sort(req, req + n, comp);
  cin >> k;
  for (int i = 0; i < k; i++) cin >> r[i];
  for (int i = 0; i < n; i++) {
    int sz = 2000000000, id = -1;
    for (int j = 0; j < k; j++) {
      if (r[j] >= req[i].first.second && r[j] < sz && used[j] == -1) {
        sz = r[j];
        id = j;
      }
    }
    if (id == -1) continue;
    used[id] = req[i].second;
    accept++;
    sum += req[i].first.first;
  }
  printf("%d %d\n", accept, sum);
  for (int i = 0; i < k; i++) {
    if (used[i] == -1) continue;
    printf("%d %d\n", used[i] + 1, i + 1);
  }
  return 0;
}
