#include <bits/stdc++.h>
using namespace std;
struct grp {
  long long id;
  long long size;
  long long income;
};
struct tbl {
  long long id;
  long long size;
};
bool incdes(grp a, grp b) { return a.income > b.income; }
bool tblsize(tbl a, tbl b) { return a.size < b.size; }
bool fit(tbl a, grp b) { return a.size < b.size; }
int32_t main() {
  long long n;
  cin >> n;
  vector<grp> group(n);
  for (long long i = 0; i < n; i++) {
    cin >> group[i].size >> group[i].income;
    group[i].id = i + 1;
  }
  long long m;
  cin >> m;
  vector<tbl> table(m);
  for (long long i = 0; i < m; i++) {
    cin >> table[i].size;
    table[i].id = i + 1;
  }
  sort(group.begin(), group.end(), incdes);
  sort(table.begin(), table.end(), tblsize);
  long long sum = 0;
  vector<pair<long long, long long> > ans;
  for (long long i = 0; i < n; i++) {
    auto grp = group[i];
    auto tableToGive = lower_bound(table.begin(), table.end(), grp, fit);
    if (tableToGive == table.end()) continue;
    sum += grp.income;
    ans.push_back(make_pair(grp.id, tableToGive->id));
    table.erase(tableToGive);
  }
  cout << ans.size() << ' ' << sum << endl;
  for (auto p : ans) cout << p.first << ' ' << p.second << endl;
  return 0;
}
