#K14836. Maximum Path Length in a Grid

    ID: 24223 Type: Default 1000ms 256MiB

Maximum Path Length in a Grid

Maximum Path Length in a Grid

You are given T test cases. Each test case consists of a grid with dimensions N and M. In each grid, you need to compute the maximum path length defined by the formula:

[ L = \min(N, M) - 1 ]

For each test case, output the computed maximum path length. The challenge is to process multiple test cases efficiently.

Note: Make sure your solution reads input from stdin and writes output to stdout.

inputFormat

The first line contains an integer T, the number of test cases.

Each of the next T lines contains two space-separated integers, N and M, which represent the dimensions of the grid.

Input Format:

T
N1 M1
N2 M2
... 
NT MT

outputFormat

Output a single line with T space-separated integers. Each integer corresponds to the maximum path length for the respective test case.

Output Format:

L1 L2 ... LT
## sample
3
2 3
4 7
10 5
1 3 4