NIO has a tree

rooted at

.
He defines the hash function of

as
%3D%5Cleft(%5Csum%5Climits_%7Bi%3D1%7D%5En%5Csum%5Climits_%7Bj%3Di%2B1%7D%5E%7Bn%7DX%5EiY%5EjZ%5E%7B%5Ctext%7Blca%7D(i%2Cj)%7D%5Cright)%5Cbmod%20P)
, where

and
)
is the lowest common ancestor of

and

.
Unfortunately, he lost the tree in an accident. The only thing he remembers is
)
.
Now given
)
and

, you need to reconstruct

with no more than

vertices.
输入描述:
The first line contains an integer
indicating the number of test cases.
For each test case, the only line contains four integers
%2CX%2CY%2CZ%5C%20(0%5Cle%20F(T)%3C%20P%2C%202%5Cle%20X%2CY%2CZ%5Cle%20P%20-%202))
.
It is guarenteed that

are chosen randomly from range

.
输出描述:
For each test case, output
lines, where
is the number of vertices of the tree.
The first line output
. You should make sure that
.
The next
lines output two integers
indicating an edge in your tree. These
edges should form a tree.