#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<pair<int, int>, int>> groups(n);
  for (int i = 0; i < n; i++)
    cin >> groups[i].first.second >> groups[i].first.first,
        groups[i].second = i;
  sort(groups.rbegin(), groups.rend());
  int m;
  cin >> m;
  vector<pair<int, int>> tables(m);
  for (int i = 0; i < m; i++) cin >> tables[i].first, tables[i].second = i;
  sort(tables.begin(), tables.end());
  bool taken[1007] = {0};
  int ans = 0;
  vector<pair<int, int>> p;
  for (int i = 0; i < groups.size(); i++) {
    for (int j = 0; j < tables.size(); j++) {
      if (!taken[j] && tables[j].first >= groups[i].first.second) {
        p.push_back({groups[i].second + 1, tables[j].second + 1});
        ans += groups[i].first.first;
        taken[j] = 1;
        break;
      }
    }
  }
  cout << p.size() << " " << ans << '\n';
  for (auto i : p) cout << i.first << " " << i.second << '\n';
}
