#include <bits/stdc++.h>
#pragma comment(linker, "/stack:336777216")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using vec3 = array<T, 3>;
template <typename T>
using vec2 = array<T, 2>;
template <typename T, size_t _bits>
using mat2d = array<array<T, _bits>, _bits>;
struct hashing {
  size_t operator()(pair<int, int> p) const {
    return std::hash<size_t>()((size_t(p.first) << 32) + p.second);
  }
};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  unordered_map<pair<int, int>, vector<int>, hashing> revv;
  for (int i = 0; i < n; i++) {
    int c, p;
    cin >> c >> p;
    v[i] = {p, -c};
    revv[{p, -c}].push_back(i);
  }
  sort(v.rbegin(), v.rend());
  int k;
  cin >> k;
  vector<int> t(k);
  unordered_map<int, vector<int>> revt;
  for (int i = 0; i < k; i++) {
    cin >> t[i];
    revt[t[i]].push_back(i);
  }
  sort(t.begin(), t.end());
  int ans = 0;
  int cnt = 0;
  stringstream ss;
  for (int i = 0; i < n; i++) {
    auto it = lower_bound(t.begin(), t.end(), -v[i].second);
    if (it != t.end()) {
      ans += v[i].first;
      cnt++;
      ss << revv[v[i]][0] + 1 << " " << revt[*it][0] + 1 << "\n";
      revv[v[i]].erase(revv[v[i]].begin());
      revt[*it].erase(revt[*it].begin());
      t.erase(it);
    } else {
    }
  }
  cout << cnt << " " << ans << "\n" << ss.str();
  return 0;
}
