#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-9;
struct T {
  int c, p, id;
  T() {}
  T(int c, int p, int id) : c(c), p(p), id(id) {}
};
int c, p, n, k;
vector<vector<int> > g(1001, vector<int>(1001, inf));
vector<T> Q;
vector<pair<int, int> > S;
inline bool cmp(const T &a, const T &b) {
  return a.p > b.p || a.p == b.p && a.c < b.c;
}
inline bool cmp2(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first < b.first;
}
int main() {
  cin >> n;
  Q.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> c >> p;
    Q[i] = T(c, p, i);
  }
  cin >> k;
  S.resize(k);
  for (int i = 0; i < k; i++) {
    cin >> c;
    S[i] = make_pair(c, i);
  }
  int cost = 0, cnt = 0;
  vector<pair<int, int> > ans;
  sort(Q.begin(), Q.end(), &cmp);
  sort(S.begin(), S.end(), &cmp2);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (Q[i].c <= S[j].first) {
        cost += Q[i].p;
        S[j].first = -1;
        cnt++;
        ans.push_back(make_pair(Q[i].id + 1, S[j].second + 1));
        break;
      }
    }
  }
  cout << cnt << ' ' << cost << endl;
  for (int i = 0; i < cnt; i++)
    cout << ans[i].first << ' ' << ans[i].second << endl;
}
