Unique Routes

3.4

5 votes
Problem

Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.

enter image description here

How many such routes are there through a N×M grid? As answer can be very large, print it modulo 10^9+7.

Input Format:-
The first line contains an integer T , i.e., number of test cases. Next T lines will contain integers N and M.

Output Format:-
Print the values corresponding to each test case.

Constraints:-

1 <= T <= 10^3
1 <= N <= 500
1 <= M <= 500

Sample Input
2
2 2
3 2
Sample Output
6
10
Time Limit: 2
Memory Limit: 256
Source Limit:
Contributers:
Editor Image

?