#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int maxn = 2e3 + 11;
int N, M, K;
int c[maxn], p[maxn], r[maxn];
struct Req {
  int c, p, idx;
  bool operator<(const Req& rhs) const { return p > rhs.p; }
} req[maxn];
struct Rec {
  int r, idx;
  bool operator<(const Rec& rhs) const { return r < rhs.r; }
} rec[maxn];
vector<int> G[maxn];
int mx[maxn], my[maxn], vis[maxn];
bool DFS(int ux) {
  vis[ux] = 1;
  for (int i = 0; i < G[ux].size(); i++) {
    int uy = G[ux][i];
    if (vis[uy]) continue;
    vis[uy] = 1;
    if (my[uy] == -1 || DFS(my[uy])) {
      mx[ux] = uy;
      my[uy] = ux;
      return true;
    }
  }
  return false;
}
int BiMatch() {
  int cnt = 0;
  memset(mx, -1, sizeof(mx));
  memset(my, -1, sizeof(my));
  for (int ux = 1; ux <= N; ux++) {
    if (mx[ux] != -1) continue;
    memset(vis, 0, sizeof(vis));
    if (DFS(ux)) cnt++;
  }
  return cnt;
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++)
    scanf("%d%d", &c[i], &p[i]), req[i] = {c[i], p[i], i};
  sort(req + 1, req + N + 1);
  cin >> K;
  for (int i = 1; i <= K; i++) scanf("%d", &r[i]), rec[i] = {r[i], i};
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= K; j++) {
      if (req[i].c <= rec[j].r) {
        G[i].push_back(N + j);
        G[N + j].push_back(i);
      }
    }
  }
  int n = BiMatch();
  int ww = 0;
  for (int i = 1; i <= N; i++) {
    if (mx[i] != -1) ww += req[i].p;
  }
  printf("%d %d\n", n, ww);
  for (int j = 1; j <= K; j++) {
    if (my[N + j] != -1) printf("%d %d\n", req[my[N + j]].idx, rec[j].idx);
  }
  return 0;
}
