#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
void openfile() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
bool compare(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) {
  return a.second.second > b.second.second;
}
vector<pair<int, int>> w;
pair<int, pair<int, int>> MIN(pair<int, pair<int, int>> a,
                              pair<int, pair<int, int>> b) {
  return a.second.second < b.second.second ? a : b;
}
pair<int, pair<int, int>> BS(int low, int high, int val,
                             pair<int, pair<int, int>> last = {-1,
                                                               {-1, INT_MAX}}) {
  if (low == high) {
    if (w[low].first >= val)
      return MIN(last, make_pair(low, make_pair(w[low].second, w[low].first)));
    else
      return last;
  } else if (low > high)
    return last;
  int mid = (low + high) / 2;
  if (w[mid].first < val)
    return BS(mid + 1, high, val, last);
  else if (w[mid].first > val)
    return BS(
        low, mid, val,
        MIN(last, make_pair(mid, make_pair(w[mid].second, w[mid].first))));
  else
    return make_pair(mid, make_pair(w[mid].second, w[mid].first));
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, pair<int, int>>> v(n);
  for (int i = 0; i < n; i++) {
    v[i].first = i + 1;
    scanf("%d %d", &v[i].second.first, &v[i].second.second);
  }
  sort((v).begin(), (v).end(), compare);
  int m;
  cin >> m;
  w.resize(m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &w[i].first);
    w[i].second = i + 1;
  }
  sort((w).begin(), (w).end());
  long long ans = 0;
  vector<pair<int, int>> res;
  for (int i = 0; i < n; i++) {
    pair<int, pair<int, int>> p = BS(0, w.size() - 1, v[i].second.first);
    if (p.first != -1) {
      ans += v[i].second.second;
      res.push_back({v[i].first, p.second.first});
      w.erase(w.begin() + p.first);
    }
  }
  cout << res.size() << " " << ans << endl;
  for (int i = 0; i < res.size(); i++)
    printf("%d %d\n", res[i].first, res[i].second);
  return 0;
}
