#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, a, b;
  cin >> n;
  priority_queue<pair<int, pair<int, int> > > pq;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    pq.push({b, {i + 1, a}});
  }
  int k;
  cin >> k;
  int A[1010];
  memset(A, 0, sizeof A);
  int maxx = 0;
  vector<vector<int> > g(1010);
  for (int i = 0; i < k; i++) {
    cin >> a;
    A[a] = a;
    g[a].push_back(i + 1);
    maxx = max(a, maxx);
  }
  int x = A[maxx];
  for (int i = maxx; i > 0; i--) {
    if (A[i] != 0)
      x = i;
    else
      A[i] = x;
  }
  long long ans = 0;
  vector<pair<int, int> > v;
  while (!pq.empty()) {
    pair<int, pair<int, int> > q = pq.top();
    pq.pop();
    int y = q.second.second;
    while (y > 0 && A[y] != y) {
      y = A[y];
    }
    if (y == 0) continue;
    v.push_back({q.second.first, g[y].back()});
    g[y].pop_back();
    if (g[y].size() == 0) A[y] = y + 1;
    ans += q.first;
  }
  int num = v.size();
  cout << num << " " << ans << "\n";
  for (int i = 0; i < num; i++) {
    cout << v[i].first << " " << v[i].second << "\n";
  }
}
