#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1005;
const int MAX_K = 1005;
struct request {
  int sz, ct, id;
} R[MAX_N];
struct table {
  int sz, id;
} T[MAX_K];
struct pairr {
  int rid, tid;
} P[MAX_K];
int vis[MAX_K];
int cmp1(const request A, const request B) {
  if (A.ct != B.ct)
    return A.ct > B.ct;
  else
    return A.sz < B.sz;
}
int cmp2(const table A, const table B) { return A.sz < B.sz; }
int main() {
  int n, k;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &R[i].sz, &R[i].ct);
    R[i].id = i;
  }
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d", &T[i].sz);
    T[i].id = i;
  }
  sort(R + 1, R + 1 + n, cmp1);
  sort(T + 1, T + 1 + k, cmp2);
  int cntR = 0, cntM = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (vis[j] == 0 && T[j].sz >= R[i].sz) {
        vis[j] = 1;
        P[cntR].rid = R[i].id;
        P[cntR].tid = T[j].id;
        cntR++;
        cntM += R[i].ct;
        break;
      }
    }
  }
  printf("%d %d\n", cntR, cntM);
  for (int i = 0; i < cntR; i++) {
    printf("%d %d\n", P[i].rid, P[i].tid);
  }
  return 0;
}
