#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const int N = 2e5 + 5;
const double pi = acos(-1);
long long n, k, total, cntr;
pair<long long, pair<long long, long long>> req[N];
vector<pair<long long, long long>> arr, temp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> req[i].second.first >> x;
    req[i].first = -1 * x;
    req[i].second.second = i + 1;
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    long long x;
    cin >> x;
    arr.push_back({x, i + 1});
  }
  sort(arr.begin(), arr.end());
  sort(req, req + n);
  for (int i = 0; i < n; i++) {
    long long low = 0, high = k - 1 - cntr, mid, ans = -1;
    while (low <= high) {
      mid = (low + high) / 2;
      if (req[i].second.first <= arr[mid].first) {
        ans = mid;
        high = mid - 1;
      } else
        low = mid + 1;
    }
    if (ans != -1) {
      total += (-1 * req[i].first);
      cntr++;
      temp.push_back({req[i].second.second, arr[ans].second});
      arr.erase(arr.begin() + ans);
    }
    if (arr.size() == 0) break;
  }
  sort(temp.begin(), temp.end());
  cout << cntr << " " << total << endl;
  for (int i = 0; i < temp.size(); i++)
    cout << temp[i].first << " " << temp[i].second << endl;
  return 0;
}
