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 JAVA):

Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProblemD {
    
    static class Shoes {
        int id;
        long size;
        long price;
        Shoes(int i, long p, long s) {
            id = i+1;
            size = s;
            price = p;
        }
        
        public String toString() {
            return "id:" + id + "/size=" + size + "/money=" + price; 
        }

    }
    
    static class Customer implements Comparable<Customer> {
        int id;
        long money;
        long req;
        Customer(int i, long m, long r) {
            id = i+1;
            money = m;
            req = r;
        }
        @Override
        public int compareTo(Customer arg0) {
            return Long.signum(money - arg0.money);
        }
        
        public String toString() {
            return "id:" + id + "/size=" + req + "/money=" + money; 
        }
        
    }
    
    public static void main(String[] args) throws IOException {
        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.valueOf(s.readLine());
        Shoes[] sho = new Shoes[n];
        Map<Long, Shoes> smap = new HashMap<Long, Shoes>();
        for (int i = 0 ; i < n ; i++) {
            String[] data = s.readLine().split(" ");
            sho[i] = new Shoes(i, Long.valueOf(data[0]), Long.valueOf(data[1]));
            smap.put(Long.valueOf(data[1]), sho[i]);
        }
        
        
        int m = Integer.valueOf(s.readLine());
        Customer[] cus = new Customer[m];
        Map<Long, List<Customer>> cmap = new HashMap<Long, List<Customer>>(); 
        for (int i = 0 ; i < m ; i++) {
            String[] data = s.readLine().split(" ");
            cus[i] = new Customer(i, Long.valueOf(data[0]), Long.valueOf(data[1]));
            long ssize = Long.valueOf(data[1]);
            if (!cmap.containsKey(ssize)) {
                cmap.put(ssize, new ArrayList<Customer>());
            }
            cmap.get(ssize).add(cus[i]);
        }
        
        Arrays.sort(sho, new Comparator<Shoes>(){
            public int compare(Shoes a, Shoes b) {
                return Long.signum(a.size - b.size);
            }
        });
        
        
        for (long key : cmap.keySet()) {
            List<Customer> cuslist = cmap.get(key);
            Collections.sort(cuslist);
        }
        
        long[][] dp = new long[n+1][4];
        int[][][] prev = new int[n+1][4][4];
        for (int i = 0 ; i <= n ; i++) {
            Arrays.fill(dp[i], -1);
        }
        dp[0][0] = 0;
        for (int i = 0 ; i < n ; i++) {
            for (int f = 0 ; f <= 2 ; f++) {
                if (dp[i][f] <= -1) {
                    continue;
                }
                
                if (dp[i+1][0] < dp[i][f]) {
                    dp[i+1][0] = dp[i][f];
                    prev[i+1][0][0] = i;
                    prev[i+1][0][1] = f;
                    prev[i+1][0][2] = -1;
                }
                
                // f = 0 / 制約なし
                // f = 1 / 前の靴がサイズ-1の客(best)を取った
                
                long price = sho[i].price;
                long size = sho[i].size;
                
                if (cmap.containsKey(size)) {
                    List<Customer> clist = cmap.get(size);
                    int toflag = 0;
                    if (i <= n - 2 && sho[i+1].size == size + 1) {
                        toflag = 1;
                    }
                    for (int c = 0 ; c < clist.size() ; c++) {
                        Customer cu = clist.get(c);
                        if (cu.money >= price) {
                            if (c < clist.size() - 1) {
                                toflag = 0;
                            }
                            if (dp[i+1][toflag] < dp[i][f] + price) {
                                dp[i+1][toflag] = dp[i][f] + price;
                                prev[i+1][toflag][0] = i;
                                prev[i+1][toflag][1] = f;
                                prev[i+1][toflag][2] = cu.id;
                            }
                            break;
                        }
                    }
                }
                
                if (cmap.containsKey(size-1)) {
                    List<Customer> clist = cmap.get(size-1);
                    int toflag = 0;
                    int fromc = 0;
                    int toc = clist.size();
                    if (f == 0) {
                        fromc = clist.size()-1;
                    } else {
                        toc = clist.size()-1;
                    }
                    for (int c = fromc ; c < toc ; c++) {
                        Customer cu = clist.get(c);
                        if (cu.money >= price) {
                            if (dp[i+1][toflag] < dp[i][f] + price) {
                                dp[i+1][toflag] = dp[i][f] + price;
                                prev[i+1][toflag][0] = i;
                                prev[i+1][toflag][1] = f;
                                prev[i+1][toflag][2] = cu.id;
                            }
                            break;
                        }
                    }
                }
            }
        }
        
        
        long max = 0;
        int now = n;
        int nowflag = 0;
        for (int f = 0 ; f <= 1 ; f++) {
            if (max < dp[n][f]) {
                max = dp[n][f];
                nowflag = f;
            }
        }

        Map<Integer, Integer> soldmap = new HashMap<Integer, Integer>();
        while (now >= 1) {
            int prevnow = prev[now][nowflag][0];
            int prevflag = prev[now][nowflag][1];
            int customer = prev[now][nowflag][2];
            if (customer >= 1) {
                soldmap.put(customer, sho[now-1].id);
            }
            now = prevnow;
            nowflag = prevflag;
        }
        
        System.out.println(max);
        System.out.println(soldmap.size());
        for (Integer id : soldmap.keySet()) {
            int to = soldmap.get(id);
            System.out.println(id + " " + to);
        }
    }
}