#include <bits/stdc++.h>
using namespace std;
struct node {
  long long count;
  long long money;
  long long isUsed;
  long long requestNumber;
};
bool compare(node a, node b) { return a.count < b.count ? true : false; }
bool compare1(pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first) ? true : false;
}
int main() {
  long long n;
  cin >> n;
  vector<node> a(n);
  node temp;
  temp.isUsed = false;
  for (int i = 0; i < n; i++) {
    cin >> temp.count;
    cin >> temp.money;
    temp.requestNumber = i + 1;
    a.push_back(temp);
  }
  sort(a.begin(), a.end(), compare);
  long long tables;
  cin >> tables;
  vector<pair<long long, long long> > t(tables);
  for (int i = 0; i < tables; i++) {
    cin >> t[i].first;
    t[i].second = i + 1;
  }
  sort(t.begin(), t.end(), compare1);
  long long maxMoney = 0;
  long long maxRequest = 0;
  vector<pair<long long, long long> > c;
  pair<long long, long long> req;
  long long index = -1;
  long long max = 0;
  long long total = 0;
  for (int i = 0; i < tables; i++) {
    index = -1;
    max = 0;
    int j = 0;
    for (j = 0; j < a.size(); j++) {
      if (a[j].isUsed) continue;
      if (a[j].count <= t[i].first && max < a[j].money) {
        max = a[j].money;
        index = j;
      }
    }
    if (index != -1) {
      req.first = a[index].requestNumber;
      req.second = t[i].second;
      a[index].isUsed = true;
      c.push_back(req);
      total = total + max;
    }
  }
  cout << c.size() << " " << total << endl;
  for (int i = 0; i < c.size(); i++) {
    cout << c[i].first << " " << c[i].second << endl;
  }
  return 0;
}
