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;
namespace FastIO_ {
template <typename T>
T read() {
  T x = 0;
  int f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x * f;
}
template <typename T>
void _print(T x) {
  if (x > 9) _print(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
void print(T x, char c) {
  if (x < 0) putchar('-'), x = -x;
  _print(x);
  if (c) putchar(c);
}
}  // namespace FastIO_
namespace BIT_ {
template <typename T>
struct BIT {
  int Size;
  vector<T> Num;
  BIT<T>() { memset(Num, 0, sizeof Num); }
  BIT<T>(int S) { Num.resize(Size = S, 0); }
  void Update(T x, int pos) {
    for (int i = pos; i <= Size; i += (i & -i)) Num[i] += x;
  }
  T GetSum(int pos) {
    T ret = 0;
    for (int i = pos; i > 0; i -= (i & -i)) ret += Num[i];
    return ret;
  }
};
}  // namespace BIT_
namespace Math_ {
template <typename T1, typename T2>
T1 Pow(T1 x, T2 y, int MOD) {
  T1 ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % MOD;
    y >>= 1;
    x = x * x % MOD;
  }
  return ret;
}
void GetPrime(int N, vector<int> &Prime) {
  vector<int> vis;
  vis.resize(N + 5, 0);
  for (int i = 2; i <= N; i++) {
    if (!vis[i]) Prime.push_back(i);
    for (int j = 0; j < int(Prime.size()) && Prime[j] * i <= N; j++) {
      vis[Prime[j] * i] = 1;
      if (i % Prime[j] == 0) break;
    }
  }
}
template <typename T>
void Divide(T N, vector<pair<int, int> > &A, vector<int> Prime) {
  for (int i = 0; i < int(Prime.size()); i++) {
    int p = Prime[i], cnt = 0;
    while (N % p == 0) N /= p, cnt++;
    if (cnt) A.push_back(make_pair(p, cnt));
  }
  if (N > 1) A.push_back(make_pair(N, 1));
}
void GetFac(int N, int MOD, int *fac) {
  fac[0] = 1;
  for (int i = 1; i <= N; i++) fac[i] = (long long)fac[i - 1] * i % MOD;
}
void GetFac(int N, int MOD, int *fac, int *facInv) {
  GetFac(N, MOD, fac);
  facInv[N] = Pow<int, int>(fac[N], MOD - 2, MOD);
  for (int i = N - 1; i >= 1; i--)
    facInv[i] = (long long)facInv[i + 1] * (i + 1) % MOD;
}
void GetC(int N, int **C, int MOD) {
  C[0][0] = 1;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= i; j++)
      C[i][j] = ((long long)C[i - 1][j - 1] + (long long)C[i - 1][j]) % MOD;
}
int calC(int N, int M, int MOD, int *fac, int *facInv) {
  if (M > N) return 0;
  return (long long)fac[N] * facInv[N - M + 1] % MOD * facInv[M] % MOD;
}
int calC(int N, int M, int MOD) {
  if (M > N) return 0;
  if (M > N - M) M = N - M;
  int ret = 1, cnt = 1;
  for (int i = N; i >= N - M + 1; i--)
    ret = (long long)ret * i / cnt % MOD, cnt++;
  return ret;
}
int calA(int N, int M, int MOD, int *fac, int *facInv) {
  if (M > N) return 0;
  return (long long)fac[N] * facInv[N - M + 1] % MOD;
}
int calA(int N, int M, int MOD) {
  if (M > N) return 0;
  int ret = 1;
  for (int i = N; i >= N - M + 1; i--) ret = (long long)ret * i % MOD;
  return ret;
}
}  // namespace Math_
namespace Graph_ {
struct Graph {
  int N, M;
  vector<int> Match, vis;
  vector<vector<int> > G;
  Graph() {
    N = 0, M = 0, G.clear();
    Match.clear(), vis.clear();
  }
  Graph(int Size) { G.resize(Size + 5, vector<int>(0, 0)); }
  bool MaxMatch_dfs(int u, int id) {
    for (int i = 0; i < int(G[u].size()); i++) {
      int v = G[u][i];
      if (vis[v] != id) {
        vis[v] = id;
        if (!Match[v] || MaxMatch_dfs(Match[v], id)) {
          Match[v] = u;
          Match[u] = v;
          return 1;
        }
      }
    }
    return 0;
  }
  int MaxMatch(int X) {
    int ret = 0;
    Match.clear();
    Match.resize(N + 5, 0);
    vis.resize(N + 5, 0);
    for (int i = 1; i <= X; i++)
      if (!Match[i]) ret += MaxMatch_dfs(i, i);
    return ret;
  }
};
}  // namespace Graph_
using namespace FastIO_;
using namespace Graph_;
int N, M;
Graph A(2 * 100000);
struct Shoes {
  int C, S, ID;
} P[100000 + 5];
map<int, int> cnt;
bool cmp(Shoes i, Shoes j) { return i.C > j.C; }
int main() {
  N = read<int>();
  for (int i = 1; i <= N; i++)
    P[i].C = read<int>(), P[i].S = read<int>(), P[i].ID = i;
  ;
  sort(P + 1, P + N + 1, cmp);
  for (int i = 1; i <= N; i++) cnt[P[i].S] = i;
  M = read<int>();
  for (int i = 1; i <= M; i++) {
    int D = read<int>(), L = read<int>();
    if (cnt.count(L) && P[cnt[L]].C <= D) A.G[cnt[L]].push_back(i + N);
    if (cnt.count(L + 1) && P[cnt[L + 1]].C <= D)
      A.G[cnt[L + 1]].push_back(i + N);
  }
  A.N = N + M;
  int tmp = A.MaxMatch(N);
  long long Ans = 0;
  for (int i = 1; i <= N; i++)
    if (A.Match[i]) Ans += P[i].C;
  print<long long>(Ans, '\n'), print<int>(tmp, '\n');
  for (int i = 1; i <= N; i++)
    if (A.Match[i]) print<int>(A.Match[i] - N, ' '), print<int>(P[i].ID, '\n');
}