#include <bits/stdc++.h>
using namespace std;
struct Req {
  int num, tot, val;
};
Req arr[1002];
bool compare(Req a, Req b) {
  if (a.val != b.val) return a.val > b.val;
  return a.tot < b.tot;
}
multiset<int> table;
vector<int> cap[1002];
vector<pair<int, int> > ans;
int main() {
  int n, i, k;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> arr[i].tot >> arr[i].val;
    arr[i].num = i + 1;
  }
  sort(arr, arr + n, compare);
  cin >> k;
  for (i = 1; i <= k; i++) {
    int z;
    cin >> z;
    cap[z].push_back(i);
    table.insert(z);
  }
  int s = 0;
  multiset<int>::iterator it;
  for (i = 0; i < n; i++) {
    it = table.lower_bound(arr[i].tot);
    if (it == table.end()) continue;
    s += arr[i].val;
    ans.push_back(make_pair(arr[i].num, cap[(*it)].back()));
    cap[(*it)].pop_back();
    table.erase(it);
  }
  cout << ans.size() << " " << s << endl;
  for (i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
