P16496 碧水涵空净,临流叹若浮 (Clear blue water mirrors the empty sky; standing by the stream, one sighs that all things drift)

Background

In spring, the ice and snow melt and all things come back to life.

Description

zxh has come to the countryside. The countryside is a rectangle with $(n+1) \times (m+1)$ intersections arranged in a grid, and any two 4-adjacent intersections are connected by a road. These roads enclose $n \times m$ squares. zxh wants to plant flowers or grass on every road. However, to keep the whole scene beautiful, for every square, among the four roads around it, two roads must have flowers and the other two must have grass. Since zxh thinks flowers look better than grass, he wants to ask you: what is the maximum number of roads that can have flowers? In addition, for relatively small countrysides, zxh wants to know one possible construction. See the Output Format section for details. **This problem uses multiple test cases.**

Input Format

The first line contains an integer $t$, the number of test cases. The next $t$ lines each contain two integers $op, n, m$, meaning that the grid has length $n$ and width $m$, and the output mode for the current test case is $op$.

Output Format

For each test case: The first line contains an integer $ans$, the answer. If $op = 1$, output a construction next. > The construction consists of $ans$ lines. Each line contains four integers $x_1, y_1, x_2, y_2$, meaning that the edge between $(x_1, y_1)$ and $(x_2, y_2)$ has flowers planted on it. > > Here $(a, b)$ means the point in row $a$ and column $b$ (all indices start from $1$).

Explanation/Hint

**This problem uses bundled tests.** |Subtask|$n,m\le$|Special property|Points| |:--------:|:--:|:--------:|:-:| |#1|$3$|A| $5$ | |#2|$20$|^| $7$ | |#3|$10^5$|^| $13$ | |#4|$10^9$| B | $11$ | |#5|^| C | $17$ | |#6|^| None | $47$ | Special property A: $t \le 10$. Special property B: both $n$ and $m$ are even. Special property C: $op = 0$ is guaranteed. For $100\%$ of the data, $1 \le t \le 10^5$ and $1 \le n,m \le 10^9$. It is guaranteed that, within the same test file, all test cases with $op = 1$ satisfy $\sum nm \le 4 \times 10^5$. Translated by QwenWork