Any matrix with rows and columns occupies N \times M cells in computer memory, just as any matrix with rows and columns does. Rows are numbered from to N - 1, and columns from to M - 1. The matrix is stored in memory in row-major order, which for matrix means the sequence: A_{0,0}, A_{0,1}, , A_{0, M - 1}, A_{1, 0}, A_{1, 1}, , A_{N - 1, M - 1}, so that adjacent elements occupy adjacent memory cells.
Matrix is called the transpose of matrix if B_{i, j} = A_{j, i} for all valid and . Clearly, if matrix is transposed, it can be placed in the position of matrix itself. Then transposition can be seen as a permutation of some elements of matrix . It is also clear that not all elements actually move; some remain immovable. For example, the first element of the first row and the last element of the last row remain immovable after transposition of any matrix.
The first line of the input file contains the integer (0 < T < 100) — the number of tests. Each of the following lines contains two integers and separated by a space, the dimensions of the matrix (0 < N, M < 2147483648).
For each test, output one line containing the number of immovable elements of the corresponding matrix.
Example 1