#include <bits/stdc++.h>
using namespace std;
long long bin_pow(long long a, long long b, long long m) {
  long long res = 1;
  while (b) {
    if (b & 1) res *= a, res %= m;
    a *= a;
    a %= m;
    b >>= 1;
  }
  return res;
}
int main() {
  int n, k, sum = 0;
  cin >> n;
  vector<pair<pair<int, int>, int> > v(n);
  vector<pair<int, int> > ans;
  for (int i = 0; i < n; i++) {
    cin >> v[i].first.second >> v[i].first.first;
    v[i].second = i + 1;
  }
  cin >> k;
  set<pair<int, int> > gr;
  for (int i = 0; i < k; i++) {
    int u;
    cin >> u;
    gr.insert({u, i + 1});
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < n && k != 0; i++) {
    pair<int, int> a = {v[i].first.second, 0};
    set<pair<int, int> >::iterator it = gr.lower_bound(a);
    if (it != gr.end()) {
      sum += v[i].first.first;
      ans.push_back({v[i].second, (*it).second});
      gr.erase({(*it).first, (*it).second});
    }
  }
  cout << ans.size() << " " << sum << endl;
  for (auto i : ans) {
    cout << i.first << " " << i.second << endl;
  }
  return 0;
}
