#include <bits/stdc++.h>
using namespace std;
long long max(long long x, long long y) {
  if (x > y) return x;
  return y;
}
long long min(long long x, long long y) {
  if (x < y) return x;
  return y;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<tuple<int, int, int>> groups;
  vector<pair<int, int>> tables;
  for (int i = 0; i < n; i++) {
    int c, p;
    cin >> c >> p;
    groups.push_back(make_tuple(p, c, i + 1));
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int r;
    cin >> r;
    tables.push_back(make_pair(r, i + 1));
  }
  sort(groups.begin(), groups.end());
  sort(tables.begin(), tables.end());
  long long value = 0;
  vector<pair<int, int>> ans;
  for (int i = groups.size() - 1; i >= 0; i--) {
    int lb = 0;
    int ub = tables.size() - 1;
    while (lb <= ub) {
      int mid = (lb + ub) / 2;
      if (tables[mid].first < get<1>(groups[i]))
        lb = mid + 1;
      else
        ub = mid - 1;
    }
    if (lb < tables.size()) {
      ans.push_back(make_pair(get<2>(groups[i]), tables[lb].second));
      value += get<0>(groups[i]);
      tables.erase(tables.begin() + lb);
    }
  }
  cout << ans.size() << " " << value << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
