Escape along Water Pipe
题号:NC223602
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
Special Judge, 64bit IO Format: %lld

题目描述

You're trapped into a map with  grids, each grid has a strange water pipe.

There are six types of water pipes, denote them as ID



You are located at the top of grid  and you want to reach the bottom of grid . In each step, you should travel along the pipe and move to another grid.



Before each move, you can do beautiful magic once: pick one of the degrees from , select any number of grids except the one you are located at, and rotate their water pipes with the same degree you pick in the clockwise direction. Note that after you step in a grid along the water pipe, you must walk along the other end of the pipe to leave this grid.

You may step in the same grid multiple times, and the direction can be different every time you enter.

Determine whether you can escape from the entrance to the exit successfully.

输入描述:

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains two integers indicating the size of the map.

In the next  lines, there are  integers , indicating the ID of waterpipe in each grid.

It's guaranteed that the sum of  over all test cases does not exceed .

输出描述:

For each test case, output 'YES' if you can escape from the map, otherwise output 'NO'.

If the answer is YES, then output a valid solution from the top of  to the bottom of . You should first output an integer  indicating the length of your operations, and then output  lines to describe your escaping line.

If you try to rotate some cells, first output two integers , indicating the number of cells and the degree you rotate, and then output  integers , indicating the cells you rotate. Two consecutive rotation requests are not allowed.

If you try to step into another cell, output three integers , indicating the next cell you pass by. You should assure that the first pair of  is , the last pair of  is , and your direction when stepping into the last cell is downward.

If there are multiple solutions, you can print any of them. 

Your submission is not accepted if the total number of  you output (including the cells you rotate and the cells you pass by) exceeds .
示例1

输入

复制
2
2 2
4 5
0 1
2 2
0 1
2 3

输出

复制
YES
5
2 90 1 1 2 1
0 1 1
0 2 1
2 180 1 2 2 2
0 2 2
NO