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>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;
const long long N = 1e6 + 100, OO = 1e9 + 7, T = 1e5 + 10, M2 = 1e9 + 7,
                M = 1e9 + 7, P = 6151, SQ = 800, lg = 70;
long long c[N], s[N], cp[N], sp[N], dp[N], is[N], id[N], fu[N], dk[N];
vector<long long> g[N];
vector<pair<long long, long long> > ans;
void solve(long long i, bool b) {
  if (!i) return;
  if (b) {
    ans.push_back({fu[i], id[i] + 1});
    if (is[i] + dp[i - 1] == dk[i])
      solve(i - 1, false);
    else
      solve(i - 1, true);
    return;
  }
  if (dp[i] == dp[i - 1]) {
    solve(i - 1, false);
    return;
  }
  long long num = 0, sz = 0, sz2 = 0;
  for (auto u : g[i]) {
    if (is[i - 1] <= cp[u]) {
      num++;
      if (num == 1)
        sz = u;
      else
        sz2 = u;
    }
    if (is[i - 1] != 0 && is[i - 1] <= cp[u] &&
        dp[i] == max(dk[i - 2], dp[i - 2]) + is[i - 1]) {
      ans.push_back({u + 1, id[i - 1] + 1});
      if (dp[i] == dp[i - 2] + is[i - 1]) {
        solve(i - 2, false);
        return;
      } else {
        solve(i - 2, true);
        return;
      }
    }
    if (is[i] != 0 && is[i] <= cp[u] && dp[i] == dp[i - 1] + is[i]) {
      ans.push_back({u + 1, id[i] + 1});
      solve(i - 1, false);
      return;
    }
  }
  for (auto u : g[i]) {
    if (cp[u] < is[i]) continue;
    if (num > 0 && sz != u &&
        dp[i] == max(dk[i - 2], dp[i - 2]) + is[i] + is[i - 1]) {
      ans.push_back({u + 1, id[i] + 1});
      ans.push_back({sz + 1, id[i - 1] + 1});
      if (dp[i] == dp[i - 2] + is[i] + is[i - 1]) {
        solve(i - 2, false);
        return;
      } else {
        solve(i - 2, true);
        return;
      }
    } else if (num > 1 &&
               dp[i] == max(dk[i - 2], dp[i - 2]) + is[i] + is[i - 1]) {
      ans.push_back({u + 1, id[i] + 1});
      ans.push_back({sz2 + 1, id[i - 1] + 1});
      if (dp[i] == dp[i - 2] + is[i] + is[i - 1]) {
        solve(i - 2, false);
        return;
      } else {
        solve(i - 2, true);
        return;
      }
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n;
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    cin >> c[i] >> s[i];
    v.push_back(s[i]);
  }
  cin >> m;
  for (long long i = 0; i < m; i++) {
    cin >> cp[i] >> sp[i];
    sp[i]++;
    v.push_back(sp[i]), v.push_back(sp[i] - 1);
  }
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  for (long long i = 0; i < n; i++) {
    s[i] = upper_bound(v.begin(), v.end(), s[i]) - v.begin();
    is[s[i]] = c[i];
    id[s[i]] = i;
  }
  for (long long i = 0; i < m; i++) {
    sp[i] = upper_bound(v.begin(), v.end(), sp[i]) - v.begin();
    g[sp[i]].push_back(i);
  }
  for (long long i = 1; i <= (long long)v.size(); i++) {
    dp[i] = dp[i - 1];
    long long num = 0, sz = 0, sz2 = 0;
    for (auto u : g[i]) {
      if (is[i - 1] <= cp[u]) {
        num++;
        if (num == 1)
          sz = u;
        else
          sz2 = u;
      }
      if (is[i - 1] != 0 && is[i - 1] <= cp[u])
        dp[i] = max(dp[i], max(dk[i - 2], dp[i - 2]) + is[i - 1]);
      if (is[i] != 0 && is[i] <= cp[u]) dp[i] = max(dp[i], dp[i - 1] + is[i]);
    }
    for (auto u : g[i])
      if (is[i - 1] != 0 && is[i - 1] <= cp[u])
        if (dk[i - 1] < is[i - 1] + max(dk[i - 2], dp[i - 2]))
          dk[i - 1] = is[i - 1] + max(dk[i - 2], dp[i - 2]), fu[i - 1] = u + 1;
    if (is[i - 1] == 0 || is[i] == 0) continue;
    for (auto u : g[i]) {
      if (cp[u] < is[i]) continue;
      if (num > 0 && sz != u)
        dp[i] = max(dp[i], max(dk[i - 2], dp[i - 2]) + is[i] + is[i - 1]);
      else if (num > 1)
        dp[i] = max(dp[i], max(dk[i - 2], dp[i - 2]) + is[i] + is[i - 1]);
    }
  }
  n = (long long)v.size();
  cout << dp[n] << endl;
  solve(n, false);
  cout << (long long)ans.size() << '\n';
  for (auto u : ans) cout << u.first << " " << u.second << '\n';
  return 0;
}