#include <bits/stdc++.h>
using namespace std;
long long n, k, sum;
bool mark[(1111)];
pair<long long, long long> b[(1111)];
pair<pair<long long, long long>, long long> a[(1111)];
vector<pair<long long, long long> > ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i].first.second >> a[i].first.first, a[i].second = i + 1;
  sort(a, a + n);
  cin >> k;
  for (int i = 0; i < k; i++) cin >> b[i].first, b[i].second = i + 1;
  sort(b, b + k);
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < k; j++)
      if (b[j].first >= a[i].first.second && !mark[j]) {
        sum += a[i].first.first, ans.push_back({a[i].second, b[j].second}),
            mark[j] = 1;
        break;
      }
  }
  cout << ans.size() << " " << sum << "\n";
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << "\n";
  return 0;
}
