#include <bits/stdc++.h>
using namespace std;
struct groupsCell {
  int num;
  int capacity;
  int money;
  bool operator<(const groupsCell& a) const { return money < a.money; }
};
struct placesCell {
  int num;
  int capacity;
  bool operator<(const placesCell& a) const { return capacity < a.capacity; }
};
vector<groupsCell> groups;
vector<placesCell> places;
bool moneyCmp(const groupsCell& a, const groupsCell& b) {
  return a.money < b.money;
}
priority_queue<groupsCell> moneys;
bool cmpCapacity(const groupsCell& a, const groupsCell& b) {
  return a.capacity < b.capacity;
}
int main() {
  int n, k;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    groupsCell cell;
    cin >> cell.capacity >> cell.money;
    cell.num = i + 1;
    groups.push_back(cell);
  }
  sort(groups.begin(), groups.end(), cmpCapacity);
  cin >> k;
  for (int i = 0; i < k; ++i) {
    placesCell cell;
    cin >> cell.capacity;
    cell.num = i + 1;
    places.push_back(cell);
  }
  sort(places.begin(), places.end());
  int j = 0;
  int applications = 0;
  int allMoney = 0;
  vector<pair<int, int> > ans;
  for (int i = 0; i < k; ++i) {
    while (j < n && groups[j].capacity <= places[i].capacity) {
      moneys.push(groups[j]);
      ++j;
    }
    if (!moneys.empty()) {
      ++applications;
      allMoney += moneys.top().money;
      pair<int, int> a;
      a.first = moneys.top().num;
      a.second = places[i].num;
      moneys.pop();
      ans.push_back(a);
    }
  }
  cout << applications << " " << allMoney << endl;
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}
