#K7026. Counting Grid Paths

    ID: 33269 Type: Default 1000ms 256MiB

Counting Grid Paths

Counting Grid Paths

You are given an \(N \times M\) grid. Starting from the top-left corner (1,1), your task is to find the number of unique paths to reach the bottom-right corner (N,M) when you can only move either right or down.

The number of paths is determined by the binomial coefficient:

\(\binom{N+M-2}{N-1} = \frac{(N+M-2)!}{(N-1)!\,(M-1)!}\)

For each test case, compute the value accordingly.

inputFormat

The first line contains a single integer \(T\) representing the number of test cases.

Each of the following \(T\) lines contains two space-separated integers \(N\) and \(M\) corresponding to the dimensions of the grid.

outputFormat

For each test case, output a single integer on a new line representing the number of unique paths from the top-left corner (1,1) to the bottom-right corner (N,M).

## sample
3
2 2
3 2
3 3
2

3 6

</p>