spoj#BOOKWORM. Kuchu the Bookworm
Kuchu the Bookworm
In this problem, you’ll be helping a little bookworm, Kuchu.
Recently “Omuk book shop” has announced a huge sale on various books. Being a bookworm, Kuchu could not miss this opportunity and went there immediately!
When reached there, she noticed that conditions of the sale are:
- One must buy exactly B books to get the discount.
- Maximum number of pages in any book is no more than 100.
As she wants to read as much as possible, Kuchu wants to get maximum number of pages satisfying the conditions above. Now she is wondering if there are N books in the store, how many different ways are there to choose exactly B books so that the number of pages is maximum possible.
Not all books are interesting to little kids, so you are given two information about each book-
- Number of pages P.
- Interest value V. V is 1 if the book is interesting for kids and 0 otherwise.
Input
First line contains an integer T, the number of test cases.
For each test case, the first line contains two integers N and B as mentioned above. Next N lines contain two integers each Pi and Vi, number of pages and interest factor of ith book.
1 ≤ T ≤ 25
1 ≤ N ≤ 100,000
1 ≤ B ≤ N
1 ≤ Pi ≤ 100
0 ≤ Vi ≤ 1
Output
For each test case, print one integer, the number of different ways to choose exactly B interesting books from those N books so that the number of pages is maximum possible. As result can be pretty large, print it modulo 1,000,000,007 (10^9+7).
Example
Input:2
Output:
2 1
2 0
3 0
5 3
10 0
5 1
2 1
2 1
2 10
3