#include <bits/stdc++.h>
const int inf = 1000005;
using namespace std;
int n, t;
vector<pair<pair<int, int>, int>> arr;
map<int, vector<int>> mp;
vector<pair<int, int>> ans;
void func() {
  long long tot = 0LL, cnt = 0LL;
  for (int i = 0; i < int((arr).size()); ++i) {
    int m = arr[i].first.first, s = -1 * arr[i].first.second,
        indx = arr[i].second;
    auto itr = mp.lower_bound(s);
    if (itr == mp.end() || itr->second.empty()) continue;
    cnt++;
    ans.push_back({indx, itr->second.back()});
    itr->second.pop_back();
    if (itr->second.empty()) mp.erase(itr);
    tot += m;
  }
  cout << cnt << " " << tot << "\n";
  for (pair<int, int> x : ans) cout << x.first << " " << x.second << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  arr.resize(n);
  for (int i = 0; i < n; ++i) {
    int s, m;
    cin >> s >> m;
    arr[i] = {{m, -s}, i + 1};
  }
  sort((arr).begin(), (arr).end(), greater<pair<pair<int, int>, int>>());
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int s;
    cin >> s;
    mp[s].push_back(i + 1);
  }
  func();
  return 0;
}
