#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > p[1003];
pair<int, int> pp[1003];
int q1[1003], q2[1003], vis[1003];
vector<pair<int, int> > ans;
int main() {
  int n, m, tot = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i].second.first >> p[i].first;
    p[i].second.second = i + 1;
  }
  sort(p, p + n);
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> pp[i].first;
    q1[pp[i].first]++;
    pp[i].second = i + 1;
  }
  sort(pp, pp + m);
  for (int i = n - 1; i >= 0; i--) {
    if (p[i].second.first <= pp[m - 1].first) {
      for (int j = 0; j < m; j++) {
        if (p[i].second.first <= pp[j].first &&
            q2[pp[j].first] < q1[pp[j].first] && !vis[j]) {
          vis[j] = 1;
          q2[pp[j].first]++;
          tot += p[i].first;
          ans.push_back(make_pair(p[i].second.second, pp[j].second));
          break;
        }
      }
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << " " << tot << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
