#include <bits/stdc++.h>
using namespace std;
class Group {
 public:
  int id;
  int v;
  int w;
  bool operator<(const Group& other) const {
    if (w > other.w) {
      return true;
    } else if (w < other.w) {
      return false;
    } else {
      return v < other.v;
    }
    return true;
  }
};
Group r[1001];
class Table {
 public:
  Table() : r(0) {}
  int id;
  int v;
  int r;
  bool operator<(const Table& other) const { return v < other.v; }
};
Table t[1001];
int main(void) {
  int n, k;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> r[i].v >> r[i].w;
    r[i].id = i;
  }
  sort(r + 1, r + n + 1);
  cin >> k;
  for (int i = 1; i <= k; ++i) {
    cin >> t[i].v;
    t[i].id = i;
  }
  sort(t + 1, t + k + 1);
  int pay = 0;
  int count = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= k; ++j) {
      if (t[j].r == 0 && t[j].v >= r[i].v) {
        pay += r[i].w;
        count++;
        t[j].r = r[i].id;
        break;
      }
    }
  }
  cout << count << " " << pay << endl;
  for (int i = 1; i <= k; ++i) {
    if (t[i].r != 0) {
      cout << t[i].r << " " << t[i].id << endl;
    }
  }
  return 0;
}
