#include <bits/stdc++.h>
using namespace std;
const int maxdot = 1005;
bool f1[maxdot][maxdot];
int num, ansx, ansy, n, m, f[maxdot][maxdot], ans;
struct Tnode {
  int c, p, go, id;
} a[maxdot];
struct Tnode2 {
  int r, id;
} b[maxdot];
struct Tnode3 {
  int x, y;
} Ans[maxdot];
bool cmp3(Tnode3 a, Tnode3 b) { return a.y < b.y; }
bool cmp2(Tnode2 a, Tnode2 b) { return a.r > b.r; }
bool cmp(Tnode a, Tnode b) { return a.c > b.c; }
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &a[i].c, &a[i].p);
    a[i].id = i;
  }
  sort(a + 1, a + n + 1, cmp);
  cin >> m;
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i].r);
    b[i].id = i;
  }
  sort(b + 1, b + m + 1, cmp2);
  int now = 0;
  for (int i = 1; i <= n; i++) {
    for (; (now < m) && (b[now + 1].r >= a[i].c);) now++;
    a[i].go = now;
  }
  ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= a[i].go; j++) {
      if (f[i - 1][j] < f[i - 1][j - 1] + a[i].p) f1[i][j] = true;
      f[i][j] = max(f[i - 1][j], f[i - 1][j - 1] + a[i].p);
      if (ans < f[i][j]) {
        ans = f[i][j];
        ansx = i;
        ansy = j;
      }
    }
  for (int i = ansx; i >= 1; i--)
    if (f1[i][ansy] == true) {
      Ans[++num].x = a[i].id;
      Ans[num].y = b[ansy].id;
      ansy--;
    }
  cout << num << " " << ans << endl;
  for (int i = 1; i <= num; i++) cout << Ans[i].x << " " << Ans[i].y << endl;
  return 0;
}
