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;
const long long int inf = 1000000000;
const long long int mod = 1000000000 + 7;
inline void IO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); }
template <class T>
inline int CHECK(T MASK, int i) {
  return (MASK >> i) & 1;
}
template <class T>
inline T ON(T MASK, int i) {
  return MASK | (T(1) << i);
}
template <class T>
inline T OFF(T MASK, int i) {
  return MASK & (~(T(1) << i));
}
template <typename T>
inline int CNT(T MASK) {
  if (numeric_limits<T>::digits <= numeric_limits<unsigned int>::digits)
    return __builtin_popcount(MASK);
  else
    return __builtin_popcountll(MASK);
}
template <class T>
inline int RIGHT(T MASK) {
  return log2(MASK & -MASK);
}
int dx4[] = {0, 0, -1, +1};
int dy4[] = {+1, -1, 0, 0};
int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
inline void I(int& a) { scanf("%d", &a); }
inline void I(long long int& a) { scanf("%I64d", &a); }
inline void I(unsigned long long int& a) { scanf("%I64u", &a); }
inline void I(char* a) { scanf("%s", a); }
char Iarr[2000010];
inline void I(string& a) {
  scanf("%s", Iarr);
  a = Iarr;
}
template <typename T, typename... Args>
void I(T& a, Args&... args) {
  I(a);
  I(args...);
}
inline void OUT(int a) { printf("%d", a); }
inline void OUT(long long int a) { printf("%I64d", a); }
inline void OUT(const char* a) { printf("%s", a); }
inline void OUT(char* a) { printf("%s", a); }
inline void OUT(bool a) { printf("%d", a); }
inline void OUT(string a) {
  for (__typeof(a.end()) it = (a.begin()) - ((a.begin()) > (a.end()));
       it != (a.end()) - ((a.begin()) > (a.end()));
       it += 1 - 2 * ((a.begin()) > (a.end())))
    printf("%c", *it);
}
inline void OUT(unsigned long long int a) { printf("%I64u", a); }
template <typename T, typename... Args>
void OUT(T a, Args... args) {
  OUT(a);
  OUT(" ");
  OUT(args...);
}
template <typename... Args>
void O(Args... args) {
  OUT(args...);
  OUT("\n");
}
template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, pair<T1, T2> p) {
  os << "{" << p.first << ", " << p.second << "}";
  return os;
}
template <typename T>
inline ostream& operator<<(ostream& os, vector<T>& a) {
  os << "[";
  for (int i = 0; i < (int)a.size(); i++) {
    if (i) os << ", ";
    os << a[i];
  }
  os << "]";
  return os;
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << endl;
  err(++it, args...);
}
const int M = 200010;
vector<pair<int, int>> order;
struct BipartiteMatcher {
  int n, k;
  vector<vector<int>> g;
  vector<int> make_tuple;
  vector<char> used;
  vector<int> L;
  BipartiteMatcher(int nn, int kk) {
    n = nn;
    k = kk;
    g.resize(n);
    used.resize(n);
    make_tuple.resize(k);
    L.resize(n);
  }
  void AddEdge(int u, int v) { g[u].push_back(v); }
  bool try_kuhn(int v) {
    if (used[v]) return false;
    used[v] = true;
    for (size_t i = 0; i < g[v].size(); ++i) {
      int to = g[v][i];
      if (make_tuple[to] == -1 || try_kuhn(make_tuple[to])) {
        make_tuple[to] = v;
        return true;
      }
    }
    return false;
  }
  int Solve() {
    sort(order.begin(), order.end());
    int ret = 0;
    make_tuple.assign(k, -1);
    for (int v = 0; v < n; ++v) {
      int x = order[v].second;
      used.assign(n, false);
      try_kuhn(x);
      L[x] = -1;
    }
    for (int i = 0; i < k; ++i)
      if (make_tuple[i] != -1) {
        ret++;
        L[make_tuple[i]] = i;
      }
    return ret;
  }
};
int main() {
  int n;
  I(n);
  int c[n], s[n];
  map<int, int> pre;
  for (int i = 0; i < n; i++) {
    I(c[i], s[i]);
    pre[s[i]] = i;
    order.push_back(make_pair(-c[i], i));
  }
  int m;
  I(m);
  int d[m], l[m];
  for (int i = 0; i < m; i++) {
    I(d[i], l[i]);
  }
  BipartiteMatcher bpm(n, m);
  for (int i = 0; i < m; i++) {
    if (pre.find(l[i]) != pre.end()) {
      int in = pre[l[i]];
      if (c[in] <= d[i]) {
        bpm.AddEdge(in, i);
      }
    }
    if (pre.find(l[i] + 1) != pre.end()) {
      int in = pre[l[i] + 1];
      if (c[in] <= d[i]) {
        bpm.AddEdge(in, i);
      }
    }
  }
  long long int ans = 0;
  int cnt = bpm.Solve();
  for (int i = 0; i < bpm.L.size(); i++) {
    if (bpm.L[i] != -1) {
      ans += c[i];
    }
  }
  O(ans);
  O(cnt);
  for (int i = 0; i < bpm.L.size(); i++) {
    if (bpm.L[i] != -1) {
      O(bpm.L[i] + 1, i + 1);
    }
  }
  return 0;
}