#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
  return a.first > b.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<pair<int, pair<int, int> > > grps(n);
  for (int c1 = 0; c1 < n; c1++) {
    cin >> grps[c1].second.first >> grps[c1].first;
    grps[c1].second.second = c1 + 1;
  }
  sort(grps.begin(), grps.end(), comp);
  int k;
  cin >> k;
  multiset<int> sizes;
  multimap<int, int> mp_sizes;
  for (int c1 = 0; c1 < k; c1++) {
    int x;
    cin >> x;
    sizes.insert(x);
    mp_sizes.insert({x, c1 + 1});
  }
  vector<pair<int, int> > tables;
  int tot_money = 0, tot_tables = 0;
  for (int c1 = 0; c1 < n; c1++) {
    auto it = sizes.lower_bound(grps[c1].second.first);
    if (it != sizes.end()) {
      tot_tables++;
      tot_money += grps[c1].first;
      auto it2 = mp_sizes.find(*it);
      tables.push_back({grps[c1].second.second, it2->second});
      sizes.erase(it);
      mp_sizes.erase(it2);
    }
  }
  cout << tot_tables << ' ' << tot_money << endl;
  for (int c1 = 0; c1 < int(tables.size()); c1++) {
    cout << tables[c1].first << ' ' << tables[c1].second << endl;
  }
  return 0;
}
