#include <bits/stdc++.h>
using namespace std;
struct group {
  int sizee;
  int money;
  int num;
};
struct tables {
  int sizee;
  int num;
};
bool byIncomDescending(const group &g, const group gg) {
  return g.money > gg.money;
}
bool bySize(const tables &t, const tables &tt) { return t.sizee < tt.sizee; }
bool FitOrNotFit(const tables &t, const group &g) { return t.sizee < g.sizee; }
int main() {
  int n;
  cin >> n;
  vector<group> customers(n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &customers[i].sizee, &customers[i].money);
    customers[i].num = i + 1;
  }
  sort(customers.begin(), customers.end(), byIncomDescending);
  int k;
  cin >> k;
  vector<tables> tab(k);
  int sum = 0;
  for (int i = 0; i < k; i++) {
    scanf("%d", &tab[i].sizee);
    tab[i].num = i + 1;
  }
  sort(tab.begin(), tab.end(), bySize);
  vector<pair<int, int> > ans;
  for (int i = 0; i < n; i++) {
    auto group = customers[i];
    auto tableToGive = lower_bound(tab.begin(), tab.end(), group, FitOrNotFit);
    if (tableToGive == tab.end()) continue;
    sum += group.money;
    ans.push_back(make_pair(group.num, tableToGive->num));
    tab.erase(tableToGive);
  }
  cout << ans.size() << ' ' << sum << endl;
  for (auto i : ans) cout << i.first << ' ' << i.second << endl;
  return 0;
}
