#include <bits/stdc++.h>
using namespace std;
struct no {
  int id, num, yuan;
} a[10001];
struct ne {
  int id, num;
} b[10001];
struct nn {
  int id1, id2;
} c[10001];
int cmp1(no a, no b) { return a.yuan > b.yuan; }
int cmp2(ne a, ne b) { return a.num < b.num; }
int cmp3(nn a, nn b) { return a.id2 < b.id2; }
int v[10001];
int main() {
  int n;
  while (~scanf("%d", &n)) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));
    memset(v, 0, sizeof(v));
    for (int i = 1; i <= n; i++) {
      scanf("%d%d", &a[i].num, &a[i].yuan);
      a[i].id = i;
    }
    int m;
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
      scanf("%d", &b[i].num);
      b[i].id = i;
    }
    sort(a + 1, a + 1 + n, cmp1);
    sort(b + 1, b + 1 + m, cmp2);
    int sum = 0, count = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (v[j] == 1) continue;
        if (b[j].num >= a[i].num) {
          sum += a[i].yuan;
          v[j] = 1;
          c[++count].id1 = a[i].id;
          c[count].id2 = b[j].id;
          break;
        }
      }
    }
    sort(c + 1, c + 1 + count, cmp3);
    printf("%d %d\n", count, sum);
    for (int i = 1; i <= count; i++) {
      printf("%d %d\n", c[i].id1, c[i].id2);
    }
  }
  return 0;
}
