#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 22;
int n, m, p[MAXN], c[MAXN], q[MAXN], pr[MAXN], r[MAXN], res;
vector<pair<int, int> > v;
bool mark[MAXN];
bool cmp(int i, int j) { return (c[i] < c[j]); }
bool cmp2(int i, int j) { return (r[i] < r[j]); }
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i] >> p[i], q[i] = i;
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> r[i], pr[i] = i;
  sort(q + 1, q + 1 + n, cmp);
  sort(pr + 1, pr + 1 + m, cmp2);
  for (int i = 1; i <= m; i++) {
    int mx = 0, po = 0;
    for (int j = 1; j <= n; j++) {
      if (r[pr[i]] < c[q[j]]) break;
      if (mx < p[q[j]] && !mark[q[j]]) mx = p[q[j]], po = q[j];
    }
    mark[po] = true;
    if (mx != 0) v.push_back({po, pr[i]});
    res += mx;
  }
  cout << v.size() << " " << res << endl;
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << endl;
  return 0;
}
