#include <bits/stdc++.h>
using namespace std;
int dp[1001][1001] = {0}, seats[1001], req_s[1001], pay[1001], n, avail;
bitset<1001> who[1001][1001];
void solve() {
  for (int j = 1; j <= avail; j++) {
    for (int k = 1; k <= n; k++) {
      if (seats[j] >= req_s[k])
        dp[j][k] = pay[k] + dp[j - 1][k - 1], who[j][k] = who[j - 1][k - 1],
        who[j][k][k] = 1;
      if (dp[j][k] < dp[j - 1][k])
        dp[j][k] = dp[j - 1][k], who[j][k] = who[j - 1][k];
      if (dp[j][k - 1] > dp[j][k])
        dp[j][k] = dp[j][k - 1], who[j][k] = who[j][k - 1];
    }
  }
}
vector<pair<int, int> > retrace() {
  vector<pair<int, int> > ans;
  int r = avail, c = n;
  while (r != 0 && c != 0) {
    if (dp[r][c] == dp[r - 1][c]) {
      r = r - 1;
      continue;
    }
    if (dp[r][c] == dp[r][c - 1]) {
      c = c - 1;
      continue;
    }
    if (dp[r][c] == dp[r - 1][c - 1] + pay[c]) {
      ans.push_back(make_pair(c, r));
      r = r - 1;
      c = c - 1;
      continue;
    }
  }
  return ans;
}
int main() {
  vector<pair<int, pair<int, int> > > v;
  vector<pair<int, int> > v2;
  cin >> n;
  for (int j = 1; j <= n; j++)
    cin >> req_s[j] >> pay[j],
        v.push_back(make_pair(req_s[j], make_pair(pay[j], j)));
  cin >> avail;
  for (int j = 1; j <= avail; j++)
    cin >> seats[j], v2.push_back(make_pair(seats[j], j));
  int pos1[1001], pos2[1001];
  sort(v.begin(), v.end());
  sort(v2.begin(), v2.end());
  for (int j = 0; j < (int)v.size(); j++)
    pos1[j + 1] = v[j].second.second, req_s[j + 1] = v[j].first,
             pay[j + 1] = v[j].second.first;
  for (int j = 0; j < (int)v2.size(); j++)
    pos2[j + 1] = v2[j].second, seats[j + 1] = v2[j].first;
  solve();
  vector<pair<int, int> > ans = retrace();
  cout << (int)ans.size() << " " << dp[avail][n] << endl;
  for (int j = 0; j < (int)ans.size(); j++)
    cout << pos1[ans[j].first] << " " << pos2[ans[j].second] << endl;
  return 0;
}
