- Time limit: 2.00 s
- Memory limit: 512 MB
You have a graph with nodes and edges. Each node has a knob that you can turn clockwise or counterclockwise. Each knob can be in one of three positions: 0°, 120°, 240°. Initially, knob is in position .
For each knob you also know its final position, . You will need to find a way to turn knobs so that:
- in each step you turn only one knob (from one position to another position)
- two knobs that are connected by an edge are never in the same position
- after you are done, each knob is in its final position
Note that you can turn the same knob many times, to any of the positions.
Input
The first input line has two integers and : the number of knobs and edges.
Then there are lines, each with two numbers and . These indicate the current position and the final position of knob .
Finally, there are lines, each with two numbers and . This indicates that there is an edge between nodes and ; here .
The input configuration and the final configuration are valid: if there is an edge between knobs and , then and .
All inputs are such that if a solution exists, there is at least one solution with at most steps.
Output
If there is a way to turn knobs so that you can reach the final configuration, print a sequence that shows how to do it. First print one line with a number (at most ): the number of steps. Then print lines, each with a pair of numbers, and : in step you turn knob to position . Here and is 0, 120, or 240.
If there is no way to solve the problem, print only one line with value .
Constraints
Example
Input:
4 4 0 0 120 240 240 120 120 240 1 2 2 3 3 4 1 4
Output:
4 3 0 4 240 2 240 3 120
The following illustration shows the solution with four steps. Here 0° points up, 120° down right and 240° down left.