#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
  if (a.first == b.first) return a.second.first < b.second.first;
  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> > > v;
  for (int i = 1; i <= n; ++i) {
    int c, p;
    cin >> c >> p;
    v.push_back(make_pair(p, make_pair(c, i)));
  }
  int m;
  cin >> m;
  vector<pair<int, int> > a(m);
  for (int i = 0; i < m; ++i) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(a.begin(), a.end());
  sort(v.begin(), v.end(), comp);
  int mx = 0, c = 0;
  vector<pair<int, int> > ans;
  for (int i = 0; i < n; ++i) {
    int x = v[i].first;
    int y = v[i].second.first;
    int z = v[i].second.second;
    if (!z) continue;
    for (int j = 0; j < m; ++j) {
      if (a[j].first >= y && a[j].second != 0) {
        mx += x;
        ++c;
        ans.push_back(make_pair(z, a[j].second));
        a[j].second = 0;
        v[i].second.second = 0;
        break;
      }
    }
  }
  cout << c << " " << mx << "\n";
  for (int i = 0; i < c; ++i)
    cout << ans[i].first << " " << ans[i].second << "\n";
  return 0;
}
