#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
struct shoe {
  int c = 0, s = 0, id = 0;
  shoe(int C = 0, int S = 0, int ID = 0) { c = C, s = S, id = ID; }
} shoes[MAXN];
bool cmp(shoe l, shoe r) { return l.s < r.s; }
bool cmp2(shoe l, shoe r) { return l.c > r.c; }
vector<int> adj[MAXN];
int n, m, pair_[2 * MAXN];
bool mark[2 * MAXN], match[2 * MAXN];
long long answer, sz;
bool dfs(int v) {
  mark[v] = true;
  for (auto i : adj[v])
    if (!match[i + n] ||
        (!mark[i + n] && !mark[pair_[i + n]] && dfs(pair_[i + n]))) {
      match[i + n] = match[v] = mark[i + n] = true;
      pair_[v] = i + n, pair_[i + n] = v;
      return true;
    }
  return false;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> shoes[i].c >> shoes[i].s;
    shoes[i].id = i;
  }
  sort(shoes, shoes + n, cmp);
  cin >> m;
  for (int i = 0; i < m; i++) {
    int d, l;
    cin >> d >> l;
    int id = lower_bound(shoes, shoes + n, shoe(d, l, -1), cmp) - shoes;
    if (id < n && shoes[id].c <= d && shoes[id].s <= (l + 1))
      adj[shoes[id].id].push_back(i);
    id++;
    if (id < n && shoes[id].c <= d && shoes[id].s <= (l + 1))
      adj[shoes[id].id].push_back(i);
  }
  sort(shoes, shoes + n, cmp2);
  for (int i = 0; i < n; i++) {
    memset(mark, 0, sizeof(mark));
    if (dfs(shoes[i].id)) {
      answer += shoes[i].c;
      sz++;
    }
  }
  cout << answer << '\n' << sz << '\n';
  for (int i = 0; i < m; i++)
    if (match[i + n]) cout << i + 1 << ' ' << pair_[i + n] + 1 << '\n';
  return 0;
}
