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;
struct cell {
  long long sum;
  int pair, c, prev;
};
struct shoe {
  long int size, cost;
};
struct man {
  long int size, money;
};
struct pairs {
  int eq, gt;
};
int main() {
  int n;
  cin >> n;
  vector<shoe> shoes(n + 1);
  map<long int, int> sizes;
  for (int i = 1; i <= n; i++) {
    long int ci, si;
    cin >> ci >> si;
    shoes[i].cost = ci;
    shoes[i].size = si;
    sizes.insert(make_pair(si, i));
  }
  int m;
  cin >> m;
  vector<man> people(m + 1);
  multimap<long int, int> foot_sizes;
  vector<pairs> suited(m + 1);
  for (int i = 1; i <= m; i++) {
    long int di, li;
    cin >> di >> li;
    people[i].money = di;
    people[i].size = li;
    foot_sizes.insert(make_pair(li, i));
  }
  map<long int, int>::iterator iter2 = sizes.begin();
  multimap<long int, int>::iterator iter1 = foot_sizes.begin();
  for (iter1; iter1 != foot_sizes.end(); iter1++) {
    long int curs = (*iter1).first;
    int i = (*iter1).second;
    while (((*iter2).first < curs) && (iter2 != sizes.end())) iter2++;
    if (iter2 != sizes.end()) {
      int shoe_num = (*iter2).second;
      if (shoes[shoe_num].cost <= people[i].money)
        if ((*iter2).first == curs)
          suited[i].eq = shoe_num;
        else if ((*iter2).first == curs + 1)
          suited[i].gt = shoe_num;
      if (++iter2 != sizes.end()) {
        int shoe_num = (*iter2).second;
        if (shoes[shoe_num].cost <= people[i].money)
          if ((*iter2).first == curs + 1) suited[i].gt = shoe_num;
      }
      --iter2;
    }
  }
  int num = 1;
  int rec = 0;
  cell c;
  c.pair = 0;
  c.sum = 0;
  c.c = 0;
  c.prev = -1;
  multimap<long int, int>::iterator iter = foot_sizes.begin();
  vector<cell> v(4, c);
  vector<vector<cell>> vec(m + 1, v);
  vector<int> map_order(m + 1);
  long int prev_size = -10;
  for (iter; iter != foot_sizes.end(); iter++) {
    long int cur_size = (*iter).first;
    int cur_man = (*iter).second;
    map_order[num] = cur_man;
    int eq = suited[cur_man].eq;
    int gt = suited[cur_man].gt;
    long int eq_cost = 0;
    if (eq > 0) eq_cost = shoes[eq].cost;
    long int gt_cost = 0;
    if (gt > 0) gt_cost = shoes[gt].cost;
    long long prev_sum0;
    long long prev_sum1;
    long long prev_sum2;
    long long prev_sum3;
    int c0, c1, c2, c3;
    int i0 = 0, i1 = 1, i2 = 2, i3 = 3;
    if (prev_size == cur_size) {
      prev_sum0 = vec[num - 1][0].sum;
      prev_sum1 = vec[num - 1][1].sum;
      prev_sum2 = vec[num - 1][2].sum;
      prev_sum3 = vec[num - 1][3].sum;
      c0 = vec[num - 1][0].c;
      c1 = vec[num - 1][1].c;
      c2 = vec[num - 1][2].c;
      c3 = vec[num - 1][3].c;
    } else if (prev_size == cur_size - 1) {
      prev_sum0 = vec[num - 1][2].sum;
      prev_sum1 = vec[num - 1][2].sum;
      prev_sum2 = vec[num - 1][3].sum;
      prev_sum3 = vec[num - 1][3].sum;
      i1 = 2;
      i0 = 2;
      i2 = 3;
      c1 = vec[num - 1][2].c;
      c0 = c1;
      c3 = vec[num - 1][3].c;
      c2 = c3;
    } else {
      prev_sum3 = vec[num - 1][3].sum;
      prev_sum0 = prev_sum3;
      prev_sum1 = prev_sum3;
      prev_sum2 = prev_sum3;
      i0 = 3;
      i1 = 3;
      i2 = 3;
      c3 = vec[num - 1][3].c;
      c1 = c3;
      c0 = c3;
      c2 = c3;
    }
    vec[num][0].sum = prev_sum0;
    vec[num][0].prev = i0;
    vec[num][0].c = c0;
    long long sum = eq_cost + prev_sum0;
    if ((eq > 0) && (sum > prev_sum2)) {
      vec[num][2].prev = i0;
      vec[num][2].pair = eq;
      vec[num][2].sum = sum;
      vec[num][2].c = c0 + 1;
    } else {
      vec[num][2].prev = i2;
      vec[num][2].sum = prev_sum2;
      vec[num][2].c = c2;
    }
    sum = gt_cost + prev_sum0;
    if ((gt > 0) && (sum > prev_sum1)) {
      vec[num][1].prev = i0;
      vec[num][1].pair = gt;
      vec[num][1].sum = sum;
      vec[num][1].c = c0 + 1;
    } else {
      vec[num][1].prev = i1;
      vec[num][1].sum = prev_sum1;
      vec[num][1].c = c1;
    }
    sum = gt_cost + prev_sum2;
    long long sum1 = eq_cost + prev_sum1;
    if ((sum >= sum1) && (sum >= prev_sum3) && (gt > 0)) {
      vec[num][3].pair = gt;
      vec[num][3].prev = i2;
      vec[num][3].sum = sum;
      vec[num][3].c = c2 + 1;
    } else if ((sum1 >= sum) && (sum1 >= prev_sum3) && (eq > 0)) {
      vec[num][3].pair = eq;
      vec[num][3].prev = i1;
      vec[num][3].sum = sum1;
      vec[num][3].c = c1 + 1;
    } else {
      vec[num][3].prev = i3;
      vec[num][3].sum = prev_sum3;
      vec[num][3].c = c3;
    }
    prev_size = cur_size;
    num++;
  }
  num--;
  long int max = 0;
  for (int i = 0; i < 4; i++)
    if (vec[num][i].sum > vec[num][max].sum) max = i;
  cout << vec[num][max].sum << "\n" << vec[num][max].c << "\n";
  for (int i = num; i >= 0; i--) {
    if (vec[i][max].pair > 0)
      cout << map_order[i] << " " << vec[i][max].pair << "\n";
    max = vec[i][max].prev;
  }
  return 0;
}