#include <bits/stdc++.h>
using namespace std;
template <class F, class T>
T convert(F a, int p = -1) {
  stringstream ss;
  if (p >= 0) ss << fixed << setprecision(p);
  ss << a;
  T r;
  ss >> r;
  return r;
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T cube(T x) {
  return x * x * x;
}
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return s == 0 ? 0 : cntbit(s >> 1) + (s & 1);
}
const long double PI = acos(-1.0);
const long double eps = 1e-9;
const int dr[] = {-1, 0, +1, 0};
const int dc[] = {0, +1, 0, -1};
const int inf = (int)1e9 + 5;
const long long linf = (long long)1e16 + 5;
const long long mod = (long long)1e8 + 7;
vector<pair<int, pair<int, int> > > group;
vector<pair<int, int> > kq;
vector<pair<int, int> > table;
int n, m;
vector<pair<int, int> >::iterator it;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int x, y;
  for (int i = (1); i <= (n); ++i) {
    cin >> x >> y;
    group.push_back(make_pair(y, make_pair(x, i)));
  }
  sort((group).begin(), (group).end(), greater<typeof(*((group).begin()))>());
  cin >> m;
  for (int i = (1); i <= (m); ++i) {
    cin >> x;
    table.push_back(make_pair(x, i));
  }
  sort((table).begin(), (table).end());
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    pair<int, int> t = group[i].second;
    it = lower_bound(table.begin(), table.end(), make_pair(t.first, -1));
    int vt = it - table.begin();
    if (it != table.end()) {
      ans += group[i].first;
      kq.push_back(make_pair(t.second, table[vt].second));
      table.erase(it);
    }
  }
  cout << ((int)(kq).size()) << " " << ans << '\n';
  for (int i = 0; i < (((int)(kq).size())); ++i) {
    cout << kq[i].first << " " << kq[i].second << '\n';
  }
}
