Under construction

Still being built. Things may change

Table Split

Time limit1sMemory limit512 MB

Summary
Given a table filled row by row with 1 to n*m, find the single vertical or horizontal cut that makes the two part sums as close as possible.
Level

Medium6 of 10

Topics
Math, Binary search, Implementation
Solved
No attempts yet

Problem

A table has nn rows and mm columns. The cells are filled row by row with the numbers from 1 to n⋅mn \cdot m. In other words, cell (r,c)(r, c) contains (r−1)⋅m+c(r - 1) \cdot m + c.

The figure below shows such a table for n=3n = 3, m=5m = 5.

12345
678910
1112131415

Split the table with one vertical or horizontal cut along the cell sides, so that the sums of the numbers in the two parts differ as little as possible. In this problem, one test contains several queries, and you must find the optimal cut for each one.

Input

The first line contains the number of queries tt (1≤t≤1051 \le t \le 10^5). Each of the next tt lines contains two integers nn and mm (1≤n,m≤1091 \le n, m \le 10^9, 2≤n×m≤1092 \le n \times m \le 10^9).

Output

Print tt lines, one answer per line. Each answer has the form D $x$, where D is V for a vertical cut and H for a horizontal cut, and xx is the number of the column or row before which the cut is made. Rows are numbered from 1 to nn and columns from 1 to mm. If several answers are optimal, print a vertical cut if one exists. If there are still several, print the one with the smallest xx.

Examples1

  1. Example 1

    Input
    5
    1 3
    4 7
    1 10
    3 3
    3 5
    
    Expected output
    V 3
    V 5
    V 8
    H 3
    V 4