题目描述
"One does not simply walk into Mordor.
Its black gates are guarded by more than just Orcs.
There is evil there that does not sleep.
The great Eye is ever watchful.
It is a barren wasteland, riddled with fire, ash, and dust.
The very air you breathe is a poisonous fume".
-Boromir at the Council of Elrond
So it all came to an end.Frodo is on the way to enter The Evil city of Mordor. Frodo is with his friend Sam Gamgee and Gollum
are on a quest to destroy the ring.The time has came they entered into the Mordor but the way to Mount Doom from the Black Gate
is quite tricky.The field of path is arranged into the form of a grid of size n*m Frodo has to go to the Mount doom for destroying
the ring,But the task is not quite simple because of the tricky magic of Saruman.
Frodo and his team is standing on Black Gate(0,0) now and they have to go to Mount Doom(n,m). Frodo got depressed because he is not
getting how to reach to Doom.But suddenly Gollum cracked the trick of Saruman the White. According to the trick They can walk either
RIGHT or DOWN, to reach the bottom right of the grid i.e at (n,m).
Thats not enough Gollum in greed of his "My precious!" tell the trick to Frodo but again ask a riddle to him,the riddle is as
follows, Frodo has to tell Gollum the number of ways in which they can reach from Black Gate(0,0) to Mount Doom(n,m) by following the trick
Frodo can't loose now but he is not good in mathematics ,so he ask you Brilliant Programmers for help.
You have to give the number of ways mod 10^9 + 7for given input size of grid .
Note Consider the following 3*3 Grid
Hence the number of ways are 6.
Input
The first line of the input contains an integer T, the number of test cases. Each of the following T
lines contains a two space separated integers N
and M denoting the number of rows and column of grid respectively.
Output
Print the number of ways mod 10^9 + 7
as explained in the problem for each test case in a new line
Constraints
1 ≤ T ≤ 100
2 ≤ N,M ≤ 10^6SAMPLE INPUT
1
3 3
SAMPLE OUTPUT
6
Explanation
As explained in question.
输入格式
见题面
输出格式
见题面