405594: GYM102006 G Is Topo Logical?
Description
A topologicial sort of a directed graph is a linear ordering of its vertices such that for every directed edge going from u into v in the graph, u comes before v in the ordering. A commonly used example is a graph of courses, where the directed edge represents that the course u must be taken before the course v. Hence making its topological sort a possible ordering of taking courses.
Mr. Topo has a directed graph. He calculated the in-degree for each node, which is equal to the number of edges going into the node, then he ran the following algorithm to obtain a topological ordering:
- Find a node u with zero in-degree that was not processed before.
- If no such u is found, terminate the algorithm.
- Otherwise, subtract 1 from the in-degree of v for all nodes v where is a directed edge in the graph. Repeat at step 1.
Your only conditions are that the graph must not contain self-loops nor repeated edges. A self-loop is an edge from the node to itself . Note that edge is different from .
InputThe first of input contains a single integer T (1 ≤ T ≤ 370), the number of test cases.
The first line of each test case contains a single the integer n (1 ≤ n ≤ 2 × 105), the number of nodes in the graph.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai < n), where ai is the initial in-degree of node i.
The third line contains n space-separated integers b1, b2, ..., bn (0 ≤ bi ≤ ai), where bi is the final in-degree of node i.
It is gauranteed that , for each test case.
The sum of n over all test cases doesn't exceed 2 × 106.
The sum of all ai values over all test cases doesn't exceed 2 × 106.
OutputFor each test case, if there is no valid graph, output only - 1 on a single line. Otherwise, output the number of edges m on the first line, and list the m directed edges (1 ≤ u, v ≤ n) of the graph in the following m lines.
If there is more than one valid solution, output any of them.
ExampleInput3Output
5
0 1 1 1 1
0 1 1 1 1
3
0 1 0
0 1 0
5
0 2 1 1 3
0 1 1 1 2
4
3 2
2 3
2 4
2 5
-1
7
3 2
2 3
1 2
2 4
1 5
2 5
3 5