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 static java.lang.Math.*;

public class CF113_Div2_D implements Runnable {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;
	
	final boolean ONLINE_JUDGE = (System.getProperty("ONLINE_JUDGE") != null);

	public static void main(String[] args) {
		new Thread(null, new CF113_Div2_D(), "", 256 * (1L << 20)).start();
	}

	@Override
	public void run() {
		try {
			long startTime = System.currentTimeMillis();
			if (ONLINE_JUDGE) {
				in = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			} else {
				in = new BufferedReader(new FileReader("input.txt"));
				out = new PrintWriter("output.txt");
			}
			Locale.setDefault(Locale.US);
			tok = new StringTokenizer("");
			solve();
			in.close();
			out.close();
			long endTime = System.currentTimeMillis();
			System.err.println("Time = " + (endTime - startTime));
			long freeMemory = Runtime.getRuntime().freeMemory();
			long totalMemory = Runtime.getRuntime().totalMemory();
			System.err.println("Memory = " + ((totalMemory - freeMemory) >> 10));
		} catch (Throwable t) {
			t.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	/** http://pastebin.com/j0xdUjDn */
	static class Utils {

		private Utils() {}

		public static void mergeSort(int[] a) {
			mergeSort(a, 0, a.length - 1);
		}

		private static final int MAGIC_VALUE = 50;

		private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
			if (leftIndex < rightIndex) {
				if (rightIndex - leftIndex <= MAGIC_VALUE) {
					insertionSort(a, leftIndex, rightIndex);
				} else {
					int middleIndex = (leftIndex + rightIndex) / 2;
					mergeSort(a, leftIndex, middleIndex);
					mergeSort(a, middleIndex + 1, rightIndex);
					merge(a, leftIndex, middleIndex, rightIndex);
				}
			}
		}

		private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
			int length1 = middleIndex - leftIndex + 1;
			int length2 = rightIndex - middleIndex;
			int[] leftArray = new int[length1];
			int[] rightArray = new int[length2];
			System.arraycopy(a, leftIndex, leftArray, 0, length1);
			System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
			for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
				if (i == length1) {
					a[k] = rightArray[j++];
				} else if (j == length2) {
					a[k] = leftArray[i++];
				} else {
					a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
				}
			}
		}

		private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
			for (int i = leftIndex + 1; i <= rightIndex; i++) {
				int current = a[i];
				int j = i - 1;
				while (j >= leftIndex && a[j] > current) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = current;
			}
		}

	}
	
	void debug(Object... o) {
		if (!ONLINE_JUDGE) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	// solution
	
	class Boot implements Comparable<Boot> {
		int cost, size, ind;

		public Boot(int cost, int size, int ind) {
			this.cost = cost;
			this.size = size;
			this.ind = ind;
		}

		@Override
		public int compareTo(Boot o) {
			return size - o.size;
		}
		
		ArrayList<Integer> link = new ArrayList<Integer>(2);
		int who = -1;
		int lastStep = -1;

		@Override
		public String toString() {
			return String.format("(%d %d)", cost, size);
		}
	}
	
	class Man implements Comparable<Man> {
		int money, size, ind;
		
		@Override
		public String toString() {
			return String.format("(%d %d)", money, size);
		}

		public Man(int money, int size, int ind) {
			this.money = money;
			this.size = size;
			this.ind = ind;
		}
		@Override
		public int compareTo(Man o) {
			if (size == o.size) {
				return money - o.money;
			}
			return size - o.size;
		}
		ArrayList<Integer> link = new ArrayList<Integer>(2);
		int who = -1;
		int lastStep = -1;
	}

	void solve() throws IOException {
		int n = readInt();
		Boot[] b = new Boot[n];
		for (int i = 0; i < n; i++) {
			b[i] = new Boot(readInt(), readInt(), i+1);
		}
		int m = readInt();
		Man[] a = new Man[m];
		for (int i = 0; i < m; i++) {
			a[i] = new Man(readInt(), readInt(), i+1);
		}
		Arrays.sort(b);
		Arrays.sort(a);
		for (int i = 0; i < m; i++) {
			Boot boot = new Boot(-1, a[i].size, -1);
			int j = Arrays.binarySearch(b, boot);
			if (j >= 0) {
				if (b[j].cost <= a[i].money) {
					a[i].link.add(j);
					b[j].link.add(i);
				}
			}
			boot.size++;
			j = Arrays.binarySearch(b, boot);
			if (j >= 0) {
				if (b[j].cost <= a[i].money) {
					a[i].link.add(j);
					b[j].link.add(i);
				}
			}
		}
		Arrays.sort(b, new Comparator<Boot>() {
			@Override
			public int compare(Boot o1, Boot o2) {
				if (o1.cost == o2.cost) {
					return o1.size - o2.size;
				}
				return o1.cost - o2.cost;
			}
		});
		debug(a);
		debug(b);
		/*for (int bi = n-1; bi >= 0; bi--) {
			if (b[bi].who == -1) {
				for (int ai : b[bi].link) {
					if (a[ai].who == -1) {
						b[bi].who = ai;
						a[ai].who = bi;
						break;
					}
				}
			}
		}*/
		for (int bi = n-1, step = 1; bi >= 0; bi--, step++) {
			dfsFromB(a, b, bi, step);
		}
		ArrayList<Answer> ans = new ArrayList<Answer>();
		long s = 0;
		for (int i = 0; i < n; i++) {
			if (b[i].who != -1) {
				ans.add(new Answer(a[b[i].who].ind, b[i].ind));
				s += b[i].cost;
			}
		}
		out.println(s);
		out.println(ans.size());
		for (Answer an : ans) {
			out.println(an);
		}
	}
	
	private boolean dfsFromB(Man[] a, Boot[] b, int bi, int step) {
		if (b[bi].lastStep == step) return false;
		b[bi].lastStep = step;
		for (int ai : b[bi].link) {
			if (a[ai].who == -1) {
				a[ai].who = bi;
				b[bi].who = ai;
				return true;
			}
			if (dfsFromB(a, b, a[ai].who, step)) {
				a[ai].who = bi;
				b[bi].who = ai;
				return true;
			}
		}
		return false;
	}

	class Answer {
		int manIndex, bootIndex;

		public Answer(int manIndex, int bootIndex) {
			this.manIndex = manIndex;
			this.bootIndex = bootIndex;
		}

		@Override
		public String toString() {
			return manIndex + " " + bootIndex;
		}
		
	}

}