#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}
bool ssortbysec(const pair<int, pair<int, int>> &a,
                const pair<int, pair<int, int>> &b) {
  if (a.second.second != b.second.second)
    return a.second.second > b.second.second;
  else
    return a.second.first < b.second.first;
}
int mark[1005];
int main() {
  int n, k;
  cin >> n;
  vector<pair<int, int>> t;
  vector<pair<int, pair<int, int>>> r;
  for (int i = 0; i < n; ++i) {
    int c, pair;
    cin >> c >> pair;
    r.push_back(make_pair(i, make_pair(c, pair)));
  }
  cin >> k;
  for (int i = 0; i < k; ++i) {
    int tc;
    cin >> tc;
    t.push_back(make_pair(i, tc));
  }
  sort(r.begin(), r.end(), ssortbysec);
  sort(t.begin(), t.end(), sortbysec);
  long long int sum = 0, k1 = 0;
  vector<pair<int, int>> ans;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < k; j++) {
      if (r[i].second.first <= t[j].second && !mark[t[j].first]) {
        mark[t[j].first] = 1;
        sum += r[i].second.second;
        k1++;
        ans.push_back(make_pair(r[i].first, t[j].first));
        break;
      }
    }
  }
  cout << k1 << " " << sum << endl;
  for (int i = 0; i < ans.size(); ++i)
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
}
