#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
int n, k, sum;
vector<tuple<int, int, int>> vec;
vector<pi> ans;
multiset<pi> table;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int c, p;
    cin >> c >> p;
    vec.emplace_back(p, c, i);
  }
  sort(vec.rbegin(), vec.rend());
  cin >> k;
  for (int i = 1; i <= k; i++) {
    int x;
    cin >> x;
    table.insert({x, i});
  }
  for (auto [p, c, i] : vec) {
    pi temp = {c, 0};
    auto it = table.lower_bound(temp);
    if (it == table.end()) continue;
    temp = *it;
    table.erase(it);
    sum += p;
    ans.emplace_back(i, temp.second);
  }
  cout << ans.size() << " " << sum << "\n";
  for (auto [x, y] : ans) cout << x << " " << y << "\n";
}
