#include <bits/stdc++.h>
using namespace std;
struct s {
  int pe;
  int cost;
  int num;
} a[1010];
struct s1 {
  int x;
  int num;
} b[1010];
int cmp1(s x, s y) {
  if (x.cost != y.cost) {
    return x.cost > y.cost;
  } else {
    return x.pe < y.pe;
  }
}
int cmp2(s1 u, s1 v) { return u.x < v.x; }
int book[1010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i].pe, &a[i].cost);
    a[i].num = i + 1;
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i].x);
    b[i].num = i + 1;
  }
  sort(a, a + n, cmp1);
  sort(b, b + m, cmp2);
  int ans1[1010];
  int ans2[1010];
  int k = 0;
  int cnt = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (book[b[j].num] == 0 && a[i].pe <= b[j].x) {
        book[b[j].num] = 1;
        ans += (long long)a[i].cost;
        cnt++;
        ans1[k] = a[i].num;
        ans2[k] = b[j].num;
        k++;
        break;
      }
    }
  }
  printf("%d %I64d\n", cnt, ans);
  for (int i = 0; i < k; i++) {
    printf("%d %d\n", ans1[i], ans2[i]);
  }
}
