#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
const int INF = 2e9;
const long long LINF = 9e18;
const int MOD1 = 2e9 + 11;
const int MOD2 = 1e9 + 9;
const int MOD3 = 1e9 + 7;
pair<int, pair<int, int> > id[1001];
pair<int, int> tab[1001], ans[1001];
int n, k, total, p;
bool used[1001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> id[i].second.first >> id[i].first;
    id[i].second.second = i;
  }
  cin >> k;
  for (int i = 1; i <= k; i++) {
    cin >> tab[i].first;
    tab[i].second = i;
  }
  sort(id + 1, id + 1 + n);
  sort(tab + 1, tab + 1 + k);
  for (int i = n; i > 0; i--) {
    int num = id[i].second.first;
    for (int j = 1; j <= k; j++) {
      if (!used[j] && num <= tab[j].first) {
        used[j] = 1;
        ans[++p].first = id[i].second.second;
        ans[p].second = tab[j].second;
        total += id[i].first;
        break;
      }
    }
  }
  cout << p << " " << total << endl;
  for (int i = 1; i <= p; i++)
    cout << ans[i].first << " " << ans[i].second << endl;
}
