#include <bits/stdc++.h>
using namespace std;
bool sortbyfreq(const pair<pair<int, int>, int> a,
                const pair<pair<int, int>, int> b) {
  return (a.first.second > b.first.second);
}
bool sortseat(const pair<int, int> a, const pair<int, int> b) {
  return (a.first < b.first);
}
int main() {
  int n, k, i, profit = 0, c = 0, j, x, y, z;
  cin >> n;
  vector<pair<pair<int, int>, int>> v;
  vector<pair<int, int>> ans;
  vector<pair<int, int>> seat;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    v.push_back({{x, y}, i});
  }
  sort(v.begin(), v.end(), sortbyfreq);
  cin >> k;
  for (i = 0; i < k; i++) {
    cin >> z;
    seat.push_back({z, i + 1});
  }
  sort(seat.begin(), seat.end(), sortseat);
  for (i = 0; i < v.size(); i++) {
    int val = v[i].first.first;
    j = 0;
    while (seat[j].first < val) j++;
    if (j < k) {
      ans.push_back({v[i].second + 1, seat[j].second});
      seat[j].first = -1;
      c++;
      profit += v[i].first.second;
    }
  }
  cout << c << " " << profit;
  cout << "\n";
  for (i = 0; i < ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
}
