#include <bits/stdc++.h>
using namespace std;
struct c {
  long long m, p, id;
};
bool comp(c a, c b) {
  if (a.m != b.m) return a.m > b.m;
  return a.p < b.p;
}
int main() {
  long long n, k;
  cin >> n;
  vector<c> v(n);
  long long j = 0;
  for (auto &i : v) cin >> i.p >> i.m, i.id = ++j;
  cin >> k;
  j = 0;
  vector<pair<long long, long long>> t(k);
  for (auto &i : t) cin >> i.first, i.second = ++j;
  sort(v.begin(), v.end(), comp);
  sort(t.begin(), t.end());
  vector<pair<long long, long long>> ans;
  long long tot = 0;
  map<long long, long long> used;
  for (auto i : v) {
    for (auto j : t) {
      if (j.first >= i.p && used[j.second] == 0) {
        used[j.second] = 1;
        tot += i.m;
        ans.push_back({i.id, j.second});
        break;
      }
    }
  }
  cout << ans.size() << " " << tot << "\n";
  for (auto i : ans) cout << i.first << " " << i.second << "\n";
}
