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.StringTokenizer;
import java.util.TreeMap;
import java.util.Arrays;

public class D {
	
	static class Scanner
	{
		BufferedReader rd;
		StringTokenizer tk;
		public Scanner() throws IOException
		{
			rd=new BufferedReader(new InputStreamReader(System.in));
			tk=new StringTokenizer(rd.readLine());
		}
		public String next() throws IOException
		{
			if (!tk.hasMoreTokens())
			{
				tk=new StringTokenizer(rd.readLine());
				return tk.nextToken();
			}
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException
		{
			return Integer.valueOf(this.next());
		}
	}
	
	
	
	static class Customer implements Comparable<Customer>
	{
		int d;
		int l;
		int n;
		public Customer(int dd,int ll,int nn)
		{
			d=dd;
			l=ll;
			n=nn;
		}
		public int compareTo(Customer arg0) {
			return this.l - arg0.l;
		}
		public String toString()
		{
			return "("+ d +","+ l +")";
		}
		
	}
	
	static int MAXN=100010;
	
	static Customer[] array=new Customer[MAXN];
	static long[][] dp=new long[MAXN][4];
	static int[][] parent=new int[MAXN][4];
	
	static TreeMap<Integer,Integer> shoes=new TreeMap<Integer,Integer>();
	static TreeMap<Integer,Integer> in_shoes=new TreeMap<Integer,Integer>();
	static TreeMap<Integer,Integer> in_customer=new TreeMap<Integer,Integer>();
	
	static long f(int i,int mask)
	{
		long c_l=(!shoes.containsKey(array[i].l))?0:shoes.get(array[i].l);
		long c_l_1=(!shoes.containsKey(array[i].l+1))?0:shoes.get(array[i].l+1);
		if (array[i-1].l==array[i].l)
		{
			long max=dp[i-1][mask];
			parent[i][mask]=0;
			if ((mask & 2 )==0 && c_l>0 && c_l<=array[i].d)
			{
				if (c_l + dp[i-1][mask | 2]>max)
				{
					max=c_l + dp[i-1][mask | 2];
					parent[i][mask]=2;
				}
			}
			if ((mask & 1 )==0 && c_l_1>0 && c_l_1<=array[i].d)
			{
				if (c_l_1 + dp[i-1][mask | 1]>max)
				{
					max=c_l_1 + dp[i-1][mask | 1];
					parent[i][mask]=1;
				}
			}
			return max;		
		}
		if (array[i-1].l+1==array[i].l)
		{
			long max=dp[i-1][mask>>1];
			parent[i][mask]=0;
			if ((mask & 2 )==0 && c_l>0 && c_l<=array[i].d)
			{
				if (c_l + dp[i-1][1]>max)
				{
					max=c_l + dp[i-1][1];
					parent[i][mask]=2;
				}
			}
			if ((mask & 1 )==0 && c_l_1>0 && c_l_1<=array[i].d)
			{
				if (c_l_1 + dp[i-1][mask >> 1]>max)
				{
					max=c_l_1 + dp[i-1][mask >> 1];
					parent[i][mask]=1;
				}
			}
			return max;		
		}
		long max=dp[i-1][0];
		parent[i][mask]=0;
		if ((mask & 2 )==0 && c_l>0 && c_l<=array[i].d)
		{
			if (c_l + dp[i-1][0]>max)
			{
				max=c_l + dp[i-1][0];
				parent[i][mask]=2;
			}
		}
		if ((mask & 1 )==0 && c_l_1>0 && c_l_1<=array[i].d)
		{
			if (c_l_1 + dp[i-1][0]>max)
			{
				max=c_l_1 + dp[i-1][0];
				parent[i][mask]=1;
			}
		}
		return max;
	}
	
	
	public static void main(String args[]) throws IOException
	{
		Scanner sc=new Scanner();
		int nshoes=sc.nextInt();
		for(int i=0;i<nshoes;i++)
		{
			int price=sc.nextInt();
			int size=sc.nextInt();
			shoes.put(size, price);
			in_shoes.put(size, i+1);
		}
		int ncustomers=sc.nextInt();
		for(int i=0;i<ncustomers;i++)
		{
			array[i]=new Customer(sc.nextInt(),sc.nextInt(),i+1);
		}
		Arrays.sort(array,0,ncustomers);
		
		/*
		for(int i=0;i<ncustomers;i++)
			System.out.println(array[i]);*/
		dp[0][3]=0;
		dp[0][2]=(!shoes.containsKey(array[0].l+1))?0:(shoes.get(array[0].l+1)<=array[0].d)?shoes.get(array[0].l+1):0;
		dp[0][1]=(!shoes.containsKey(array[0].l))?0:(shoes.get(array[0].l)<=array[0].d)?shoes.get(array[0].l):0;
		dp[0][0]=Math.max(dp[0][2], dp[0][1]);
		
		parent[0][0]=(dp[0][0]==0)?0:(dp[0][0]==dp[0][1])?2:1;
		parent[0][2]=(dp[0][2]==0)?0:1;
		parent[0][1]=(dp[0][1]==0)?0:2;
		parent[0][3]=0;
		
		for(int i=1;i<ncustomers;i++)
		{
			for(int mask=0;mask<4;mask++)
				dp[i][mask]=f(i,mask);
		}
		
		System.out.println(dp[ncustomers-1][0]);
		if (dp[ncustomers-1][0]==0)
		{
			System.out.println("0");
			System.exit(0);
		}
		StringBuilder sb=new StringBuilder();
		int amount=0;
		int mask=0;
		int index=ncustomers-1;
		while(index>=0)
		{
			int tmp=parent[index][mask];
			if (tmp>0)
				amount++;
			if (index==0)
			{
				if (tmp==2)
					sb.append(array[index].n+" "+in_shoes.get(array[index].l)+"\n");
				else if (tmp==1)
					sb.append(array[index].n+" "+in_shoes.get(array[index].l+1)+"\n");
				break;
			}
			if (array[index-1].l==array[index].l)
			{				
				if (tmp==2)
				{
					sb.append(array[index].n+" "+in_shoes.get(array[index].l)+"\n");
					mask=mask | 2;
				}
				else if (tmp==1)
				{
					sb.append(array[index].n+" "+in_shoes.get(array[index].l+1)+"\n");
					mask=mask | 1;
				}
			    index--;
			    continue;
			}
			if (array[index-1].l+1==array[index].l)
			{
				if (tmp==2)
				{
					sb.append(array[index].n+" "+in_shoes.get(array[index].l)+"\n");
					mask=1;
				}
				else if (tmp==1)
				{
					sb.append(array[index].n+" "+in_shoes.get(array[index].l+1)+"\n");
					mask=mask >> 1;
				}
				else
					mask=mask>>1;
				index--;
				continue;
			}
			mask=0;
			if (tmp==2)
				sb.append(array[index].n+" "+in_shoes.get(array[index].l)+"\n");
			else if (tmp==1)
				sb.append(array[index].n+" "+in_shoes.get(array[index].l+1)+"\n");
			index--;
		}
		System.out.println(amount);
		System.out.print(sb.toString());
	}
	

}