Welcome to ZOJ
Select Problem
ZOJ Problem Set - 3604
Tunnel Network

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Country Far-Far-Away is a big country with N cities. But it is now under a civil war. The rebel uses the ancient tunnel network which connects all N cities with N-1 inter-city tunnels for transportation. The government army want to destroy these tunnels one by one. After several months fighting, some tunnels have been destoryed. According to the intel, the tunnel network have excatly S connected components now. And what government army further knows is that city 1, 2, ... , S belong to each of the S connected components. Since the government have little knowledge about the remaining tunnels, they ask you to calculate the number of possible networks of remaining tunnels.


There are multiple test cases. The first line of input contains an integer T (T ≤ 500) indicating the number of test cases. Then T test cases follow.

Each case contains one line containing two integer N (2 ≤ N ≤ 2000) and S (2 ≤ S ≤ N), as described above.


The number of possible networks now. Since the number might be very large, you should output the answer after modulo 1000000007.

Sample Input

3 2
4 2
5 3
100 50

Sample Output


Author: WANG, Yelei
Contest: The 9th Zhejiang Provincial Collegiate Programming Contest
Submit    Status