Problem: The warehouse in your shop has n shoe pairs. Each pair is characterized by two integers: its price ci and its size si. We know that on this very day all numbers si are different, that is, there is no more than one pair of each size.

The shop has m customers who came at the same time. The customer number i has di money and the size of his feet equals li. The customer number i can buy the pair number j, if cj ≤ di, and also if li = sj or li = sj - 1; that is, it is necessary that he has enough money to pay for the shoes. It is also necessary that the size of his feet equals to or is less by 1 than the size of the shoes he chooses.

Your task is to sell some customers pairs of shoes (a pair per person) so as to maximize the sum of the sold pairs cj that is, the profit. It is guaranteed that each customer buys no more than one pair and each pair will be bought by no more than one customer.

Input

The first input line contains the only integer n (1 ≤ n ≤ 105) — the number of shoe pairs in the warehouse. Then n lines contain the descriptions of pairs of shoes as two integers ci and si (1 ≤ ci, si ≤ 109), the numbers are separated by a space. It is guaranteed that all numbers si are different.

The next line contains an integer m (1 ≤ m ≤ 105) — the number of customers in the shop. Next m lines contain the customers' descriptions as two integers di and li (1 ≤ di, li ≤ 109), the numbers are separated by a space.

Output

In the first line print the only integer — the maximum profit you can get from selling shoes. In the second line print an integer k — the number of shoe pairs you will sell. In the following k lines print the descriptions of the sold pairs — two space-separated integers where the first number is the customer's number and the second number is the number of the shoes the customer will buy.

You can print pairs of numbers "the customer's number and the shoes' number" in any order, the customers and the pairs of shoes are numbered starting from 1 in the order in which they are given in the input. If there are several optimal answers, you are allowed to print any of them.

Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator instead.

Examples

Input

3
10 1
30 2
20 3
2
20 1
20 2


Output

30
2
2 3
1 1


Input

3
10 4
20 5
30 6
2
70 4
50 5


Output

50
2
2 3
1 2

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, ma;
map<int, long long> c;
map<int, int> m;
struct cust {
  int l;
  long long d;
  long long in;
};
long long dp[110000][5];
cust com[110000];
int a, b;
long long dprec(int in, int state) {
  long long &ret = dp[in][state];
  if (ret != -1) return ret;
  long long d1, d2;
  d1 = c[com[in].l];
  d2 = c[com[in].l + 1];
  ret = 0;
  if (ma == in) {
    if (state % 2 && com[in].d >= d2) ret = d2;
    if (state / 2 && com[in].d >= d1) ret = max(ret, d1);
    return ret;
  }
  int stat;
  long long tem;
  if ((state % 2) && com[in].d >= d2 && d2) {
    tem = d2;
    if (com[in + 1].l == com[in].l)
      tem += dprec(in + 1, state ^ 1);
    else if (com[in + 1].l == com[in].l - 1)
      tem += dprec(in + 1, 2 + (state / 2));
    else
      tem += dprec(in + 1, 3);
    ret = tem;
  }
  if (state / 2 && com[in].d >= d1 && d1) {
    tem = d1;
    if (com[in + 1].l == com[in].l)
      tem += dprec(in + 1, state ^ 2);
    else if (com[in + 1].l == com[in].l - 1)
      tem += dprec(in + 1, 2);
    else
      tem += dprec(in + 1, 3);
    ret = max(ret, tem);
  }
  if (com[in + 1].l == com[in].l)
    tem = dprec(in + 1, state);
  else if (com[in + 1].l == com[in].l - 1)
    tem = dprec(in + 1, 2 + state / 2);
  else
    tem = dprec(in + 1, 3);
  ret = max(ret, tem);
  return ret;
}
vector<int> ans1, ans2;
bool path(int in, int state) {
  long long ret = dp[in][state];
  long long d1, d2;
  d1 = c[com[in].l];
  d2 = c[com[in].l + 1];
  if (ma == in) {
    if (state % 2 && com[in].d >= d2 && ret == d2 && ret) {
      ans1.push_back(com[in].in);
      ans2.push_back(m[com[in].l + 1]);
    } else if (state / 2 && com[in].d >= d1 && ret == d1 && ret) {
      ans1.push_back(com[in].in);
      ans2.push_back(m[com[in].l]);
    }
    return false;
  }
  int stat;
  long long tem;
  a = in + 1;
  if (state % 2 && com[in].d >= d2 && d2) {
    tem = d2;
    if (com[in + 1].l == com[in].l)
      tem += dprec(in + 1, state ^ 1);
    else if (com[in + 1].l == com[in].l - 1)
      tem += dprec(in + 1, 2 + (state / 2));
    else
      tem += dprec(in + 1, 3);
    if (ret == tem) {
      if (com[in + 1].l == com[in].l)
        b = state ^ 1;
      else if (com[in + 1].l == com[in].l - 1)
        b = 2 + (state / 2);
      else
        b = 3;
      ans1.push_back(com[in].in);
      ans2.push_back(m[com[in].l + 1]);
      return true;
    }
  }
  if (state / 2 && com[in].d >= d1 && d1) {
    tem = d1;
    if (com[in + 1].l == com[in].l)
      tem += dprec(in + 1, state ^ 2);
    else if (com[in + 1].l == com[in].l - 1)
      tem += dprec(in + 1, 2);
    else
      tem += dprec(in + 1, 3);
    if (ret == tem) {
      if (com[in + 1].l == com[in].l)
        b = state ^ 2;
      else if (com[in + 1].l == com[in].l - 1)
        b = 2;
      else
        b = 3;
      ans1.push_back(com[in].in);
      ans2.push_back(m[com[in].l]);
      return true;
    }
  }
  if (com[in + 1].l == com[in].l)
    b = state;
  else if (com[in + 1].l == com[in].l - 1)
    b = 2 + state / 2;
  else
    b = 3;
  return true;
}
bool comp(cust p, cust q) { return p.l > q.l; }
int main() {
  while (cin >> n) {
    int i, j;
    for (i = 1; i <= n; i++) {
      cin >> a >> b;
      c[b] = a;
      m[b] = i;
    }
    cin >> ma;
    for (i = 1; i <= ma; i++) {
      cin >> com[i].d >> com[i].l;
      com[i].in = i;
    }
    sort(&com[1], &com[ma + 1], comp);
    memset(dp, -1, sizeof(dp));
    for (i = ma; i >= 1; i--)
      for (j = 0; j <= 3; j++) dprec(i, j);
    cout << dprec(1, 3) << endl;
    a = 1;
    b = 3;
    while (path(a, b))
      ;
    int lim = (int)ans1.size();
    cout << lim << endl;
    for (i = 0; i <= lim - 1; i++) cout << ans1[i] << " " << ans2[i] << endl;
  }
  return 0;
}