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 MarketInfo {
  MarketInfo() { assert(0); }
  MarketInfo(int price_, int product_) : price(price_), product(product_) {}
  int popMid() {
    int result = *(mid.begin());
    mid.erase(mid.begin());
    return result;
  }
  int popLeft() {
    int result = *(left.begin());
    left.erase(left.begin());
    return result;
  }
  set<int> mid;
  set<int> left;
  int price;
  int product;
};
struct Sale {
  Sale(int buyer_, int product_) : buyer(buyer_), product(product_) {}
  int buyer;
  int product;
};
static uint64_t sell(map<int, MarketInfo>::iterator start,
                     map<int, MarketInfo>::iterator end,
                     map<int, MarketInfo>& catalog, vector<Sale>& sales) {
  if (start == end) return 0;
  int currSize = (*start).first;
  MarketInfo& currMInfo = (*start).second;
  map<int, MarketInfo>::iterator nextIt = start;
  nextIt++;
  int nextSize = (*nextIt).first;
  MarketInfo& nextMInfo = (*nextIt).second;
  if (currMInfo.mid.size() > 0) {
    sales.push_back(Sale(currMInfo.popMid(), currMInfo.product));
    if (nextSize == currSize + 1) {
      nextMInfo.mid.insert(currMInfo.left.begin(), currMInfo.left.end());
    }
    return currMInfo.price + sell(nextIt, end, catalog, sales);
  } else if (currMInfo.left.size() > 1) {
    sales.push_back(Sale(currMInfo.popLeft(), currMInfo.product));
    if (nextSize == currSize + 1) {
      nextMInfo.mid.insert(currMInfo.left.begin(), currMInfo.left.end());
    }
    return currMInfo.price + sell(nextIt, end, catalog, sales);
  } else if (currMInfo.left.size() == 1) {
    int iStart = currSize;
    int iEnd = currSize + 1;
    int lowestPrice = currMInfo.price;
    int lowestSize = currSize;
    while (catalog[iEnd].mid.size() == 0 && catalog[iEnd].left.size() == 1) {
      if (catalog[iEnd].price < lowestPrice) {
        lowestPrice = catalog[iEnd].price;
        lowestSize = iEnd;
      }
      iEnd++;
    }
    if (catalog[iEnd].mid.size() > 0) {
      uint64_t profit = 0;
      for (int i = iStart; i < iEnd; i++) {
        profit += catalog[i].price;
        sales.push_back(Sale(catalog[i].popLeft(), catalog[i].product));
      }
      profit += catalog[iEnd].price;
      sales.push_back(Sale(catalog[iEnd].popMid(), catalog[iEnd].product));
      map<int, MarketInfo>::iterator it = catalog.find(iEnd + 1);
      if (it != catalog.end()) {
        (*it).second.mid.insert(catalog[iEnd].left.begin(),
                                catalog[iEnd].left.end());
      }
      it = catalog.find(iEnd);
      it++;
      return profit + sell(it, end, catalog, sales);
    } else if (catalog[iEnd].left.size() > 1) {
      uint64_t profit = 0;
      for (int i = iStart; i < iEnd; i++) {
        profit += catalog[i].price;
        sales.push_back(Sale(catalog[i].popLeft(), catalog[i].product));
      }
      profit += catalog[iEnd].price;
      sales.push_back(Sale(catalog[iEnd].popLeft(), catalog[iEnd].product));
      map<int, MarketInfo>::iterator it = catalog.find(iEnd + 1);
      assert(it != catalog.end());
      (*it).second.mid.insert(catalog[iEnd].left.begin(),
                              catalog[iEnd].left.end());
      return profit + sell(it, end, catalog, sales);
    } else {
      if (catalog[iEnd].price < lowestPrice) {
        lowestPrice = catalog[iEnd].price;
        lowestSize = iEnd;
      }
      uint64_t profit = 0;
      for (int i = iStart; i <= lowestSize - 1; i++) {
        profit += catalog[i].price;
        sales.push_back(Sale(catalog[i].popLeft(), catalog[i].product));
      }
      for (int i = lowestSize + 1; i <= iEnd; i++) {
        profit += catalog[i].price;
        sales.push_back(Sale(catalog[i - 1].popLeft(), catalog[i].product));
      }
      map<int, MarketInfo>::iterator it = catalog.find(iEnd);
      it++;
      return profit + sell(it, end, catalog, sales);
    }
  } else {
    return sell(nextIt, end, catalog, sales);
  }
}
int main() {
  int n;
  cin >> n;
  map<int, MarketInfo> catalog;
  for (int i = 0; i < n; i++) {
    int ci, si;
    cin >> ci >> si;
    catalog.insert(make_pair(si, MarketInfo(ci, i + 1)));
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int di, li;
    cin >> di >> li;
    map<int, MarketInfo>::iterator it1, it2;
    it1 = catalog.find(li);
    it2 = catalog.find(li + 1);
    bool canBuy1 = (it1 != catalog.end() && di >= (*it1).second.price);
    bool canBuy2 = (it2 != catalog.end() && di >= (*it2).second.price);
    if (canBuy1 && canBuy2) {
      (*it1).second.left.insert(i + 1);
    } else if (canBuy1) {
      (*it1).second.mid.insert(i + 1);
    } else if (canBuy2) {
      (*it2).second.mid.insert(i + 1);
    }
  }
  vector<Sale> sales;
  uint64_t profit = sell(catalog.begin(), catalog.end(), catalog, sales);
  cout << profit << endl;
  cout << sales.size() << endl;
  for (int i = 0; i < (int)sales.size(); i++) {
    cout << sales[i].buyer << " " << sales[i].product << endl;
  }
  return 0;
}