#include <bits/stdc++.h>
using namespace std;
struct node {
  int c, p, id;
} a[1010];
int n, m;
int used[1010];
int vis[1010];
bool cmp(node a, node b) {
  if (a.p == b.p)
    return a.c < b.c;
  else
    return a.p > b.p;
}
struct node2 {
  int num, id;
} num[1010];
bool cmp2(node2 a, node2 b) {
  if (a.num == b.num)
    return a.id < b.id;
  else
    return a.num < b.num;
}
int main() {
  while (cin >> n) {
    for (int i = 0; i < n; ++i) {
      scanf("%d%d", &a[i].c, &a[i].p);
      a[i].id = i + 1;
    }
    sort(a, a + n, cmp);
    scanf("%d", &m);
    for (int i = 0; i < m; ++i) {
      scanf("%d", &num[i].num);
      num[i].id = i + 1;
    }
    sort(num, num + m, cmp2);
    memset(used, 0, sizeof(used));
    memset(vis, 0, sizeof(vis));
    int tol = 0, cnt = 0;
    for (int i = 0; i < n; ++i) {
      int t = a[i].c;
      bool flag = true;
      for (int j = 0; j < m; ++j) {
        if (!used[j] && num[j].num >= t) {
          cnt++;
          tol += a[i].p;
          used[j] = true;
          vis[a[i].id] = num[j].id;
          break;
        }
      }
    }
    printf("%d %d\n", cnt, tol);
    for (int i = 0; i < n; ++i) {
      if (vis[a[i].id]) printf("%d %d\n", a[i].id, vis[a[i].id]);
    }
  }
}
