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;
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
  s << "{";
  for (int i = 0; i < t.size(); i++)
    s << t[i] << (i == t.size() - 1 ? "" : ",");
  return s << "}" << endl;
}
set<int> all;
set<int> s1[100005], s2[100005];
vector<pair<int, pair<int, int> > > but;
vector<int> kr[100005];
vector<int> lewo[100005];
int kasa[100002];
bool ob[100002];
int getuj(int roz) {
  return lower_bound((but).begin(), (but).end(),
                     make_pair(roz, make_pair(0, 0))) -
         but.begin();
}
void wywal(int nr, int skad) {
  for (int j = skad; j <= skad + 1; j++) {
    s1[j].erase(nr);
    s2[j].erase(nr);
  }
}
set<int> Q;
long long suma = 0;
vector<pair<int, int> > wyn;
void paruj(int a, int b) {
  ob[a] = 0;
  all.erase(but[b].first);
  for (int j = 0; j < kr[b].size(); j++) Q.insert(kr[b][j]);
  suma += but[b].second.second;
  wyn.push_back(make_pair(a, but[b].second.first));
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c;
    int r;
    cin >> c >> r;
    but.push_back(make_pair(r, make_pair(i, c)));
    all.insert(r);
  }
  sort((but).begin(), (but).end());
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int kas, roz;
    cin >> kas >> roz;
    kasa[i] = kas;
    vector<int> d;
    for (int r = roz; r <= roz + 1; r++) {
      if (!((all).find((r)) != (all).end())) continue;
      int nr = getuj(r);
      if (but[nr].second.second <= kas) {
        d.push_back(nr);
        kr[nr].push_back(i);
      }
    };
    lewo[i] = d;
    if (d.size() < 2) Q.insert(i);
    ob[i] = 1;
  }
  while (Q.size()) {
    int nr = *(Q.begin());
    Q.erase(Q.begin());
    if (!ob[nr]) continue;
    for (int j = 0; j < lewo[nr].size(); j++) {
      int B = lewo[nr][j];
      if (!((all).find((but[B].first)) != (all).end())) continue;
      paruj(nr, B);
    }
    ob[nr] = 0;
  }
  for (int i = 0; i < m; i++) {
    if (ob[i]) {
      if (lewo[i].size() != 2) {
        ;
        return 0;
      }
      s1[lewo[i][0]].insert(i);
      s2[lewo[i][1]].insert(i);
    }
  }
  int i = 0;
  while (i < but.size()) {
    ;
    ;
    ;
    if (s1[i].size() == 0) {
      i++;
      continue;
    }
    int j = i;
    int h = 0;
    while (s1[j].size()) {
      h += s1[j].size();
      j++;
    }
    if (h > j - i) {
      for (int r = i; r <= j; r++) {
        if (s2[r].size()) {
          int nr = *(s2[r].begin());
          suma += but[r].second.second;
          wyn.push_back(make_pair(nr, but[r].second.first));
          wywal(nr, r);
        } else {
          if (s1[r].size() == 0) {
            ;
            return 1;
          }
          int nr = *(s1[r].begin());
          suma += but[r].second.second;
          wyn.push_back(make_pair(nr, but[r].second.first));
          wywal(nr, r);
        }
      }
    } else {
      int slaby = i;
      for (int r = i; r <= j; r++) {
        if (but[r].second.second < but[slaby].second.second) slaby = r;
      }
      for (int r = i; r <= j; r++) {
        if (r == slaby) continue;
        if (s2[r].size()) {
          int nr = *(s2[r].begin());
          suma += but[r].second.second;
          wyn.push_back(make_pair(nr, but[r].second.first));
          wywal(nr, r);
        } else {
          if (s1[r].size() == 0) {
            ;
            return 1;
          }
          int nr = *(s1[r].begin());
          suma += but[r].second.second;
          wyn.push_back(make_pair(nr, but[r].second.first));
          wywal(nr, r);
        }
      }
    }
    i = j + 1;
  }
  cout << suma << "\n";
  cout << wyn.size() << "\n";
  for (int i = 0; i < wyn.size(); i++)
    cout << wyn[i].first + 1 << " " << wyn[i].second + 1 << "\n";
  return 0;
}