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.*;
import java.util.*;
import java.math.*;

public class Shoes {
    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;
    Random rnd;
    
    class Pair implements Comparable<Pair> {
        int a, b, id;

        public Pair(int a, int b, int id) {
            this.a = a;
            this.b = b;
            this.id = id;
        }
        
        public int compareTo(Pair p) {
            if(a != p.a)
                return -(a - p.a);
            
            if(b != p.b)
                return b - p.b;
            
            return id - p.b;
        }
        
        public String toString() {
            return a + " " + b;
        }
    }
    
    Pair[] shoes, buyers;
    HashMap<Integer, ArrayList<Integer>> map;
    ArrayList<Integer>[] g;
    int[] mt, used, dsu, sizes;
    int timer;
    
    boolean checkUsed(int u) {
        if(used[u] == timer)
            return true;
        
        return false;
    }
    
    void setUsed(int u) {
        used[u] = timer;
    }
    
    boolean dfs(int u) {
        if(checkUsed(u))
            return false;
        
        setUsed(u);
        
        for(int v : g[u]) {
            if(mt[v] == -1) {
                modSize(v, -1);
                mt[v] = u;
                return true;
            }
        }
        
        for(int v : g[u]) {
            if(checkSize(v) && dfs(mt[v])) {
                mt[v] = u;
                return true;
            }
        }
        
        return false;
    }
    
    int findSet(int u) {
        if(dsu[u] == u) {
            return u;
        } else {
            return dsu[u] = findSet(dsu[u]);
        }
    }
    
    void mergeEdge(int id) {
        for(int i = 0; i < g[id].size() - 1; i++) {
            int a = g[id].get(i), b = g[id].get(i + 1);
            mergeSets(a, b);
        }
    }
    
    boolean checkSize(int id) {
        id = findSet(id);
        return sizes[id] > 0;
    }
    
    void mergeSets(int a, int b) {
        a = findSet(a);
        b = findSet(b);
        
        if(a != b) {
            if(rnd.nextBoolean()) {
                dsu[a] = b;
                sizes[b] += sizes[a];
            } else {
                dsu[b] = a;
                sizes[a] += sizes[b];
            }
        }
    }
    
    void modSize(int a, int diff) {
        a = findSet(a);
        sizes[a] += diff;
    }

    void solve() throws IOException {
        int n = nextInt();
        //int n = 100000, m = 100000;
        
        shoes = new Pair[n];
        map = new HashMap<Integer, ArrayList<Integer>>();
        used = new int[n];
        g = new ArrayList[n];
        
        for(int i = 0; i < n; i++) {
            shoes[i] = new Pair(nextInt(), nextInt(), i);
            //shoes[i] = new Pair(rnd.nextInt(1000000000), rnd.nextInt(1000000000), i);
            g[i] = new ArrayList<Integer>();
        }
        
        int m = nextInt();
        
        buyers = new Pair[m];
        mt = new int[m];
        dsu = new int[m];
        sizes = new int[m];
        
        for(int i = 0; i < m; i++) {
            buyers[i] = new Pair(nextInt(), nextInt(), i);
            //buyers[i] = new Pair(rnd.nextInt(1000000000), rnd.nextInt(1000000000), i);
            
            int size = buyers[i].b;
            
            if(!map.containsKey(size)) {
                map.put(size, new ArrayList<Integer>());
            }
            
            map.get(size).add(i);
            
            mt[i] = -1;
            dsu[i] = i;
            sizes[i] = 1;
        }
        
        Arrays.sort(shoes);
        
        for(int i = 0; i < n; i++) {
            g[i] = new ArrayList<Integer>();
            
            for(int buyerSize = shoes[i].b - 1; buyerSize <= shoes[i].b; buyerSize++) {
                ArrayList<Integer> v = map.get(buyerSize);
                
                if(v != null) {
                    for(int buyedId : v) {
                        if(buyers[buyedId].a >= shoes[i].a) {
                            g[i].add(buyedId);
                        }
                    }
                }
            }
            
            Collections.shuffle(g[i]);
            
            //out.println(shoes[i].b + " " + g[i].toString());
        }
        
        for(int i = 0; i < n; i++) {
            timer = i + 1;
            
            mergeEdge(i);
            dfs(i);
            
            //out.println(i + " " + dfs(i));
        }
        
        long resCost = 0;
        
        ArrayList<Pair> res = new ArrayList<Pair>();
        
        for(int i = 0; i < m; i++) {
            int u = mt[i];
            
            if(u != -1) {
                resCost += shoes[u].a;
                res.add(new Pair(i + 1, shoes[u].id + 1, -1));
            }
        }
        
        out.println(resCost);
        
        out.println(res.size());
        
        for(Pair p : res) {
            out.println(p);
        }
    }

    public static void main(String[] args) {
        new Shoes().run();
    }

    public void run() {
        try {
            final String className = this.getClass().getName().toLowerCase();

            try {
                in = new BufferedReader(new FileReader(className + ".in"));
                out = new PrintWriter(new FileWriter(className + ".out"));
            } catch (FileNotFoundException e) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            }

            rnd = new Random();

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(42);
        }
    }

    String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = in.readLine();

            if (line == null)
                return null;

            st = new StringTokenizer(line);
        }

        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}