Under construction

Still being built. Things may change

Intranets

Memory limit1024 MB

Summary
Given M machines with randomly assigned link priorities, find the probability that greedy highest-priority routing yields exactly K intranets, modulo 1000000007.
Level

Medium7 of 10

Topics
Combinatorics, Math, Graph
Solved
No attempts yet

Problem

Apricot Rules LLC is developing a new simplified networking protocol and wants to show off its routing algorithm. In their design, a network consists of MM machines numbered from 11 to MM, and each pair of machines is connected by a direct link. Each link gets a unique integer priority from 11 to M(M−1)/2M(M-1)/2, and each machine routes traffic according to those priorities.

Unfortunately, the routing algorithm is too aggressive. It routes all traffic from a machine through the highest priority link connected to it. This may isolate some groups of machines from the others.

Formally, a machine mm uses a link ℓ\ell if and only if ℓ\ell is the highest priority link connected to mm. A link is active if at least one of the two machines it connects uses it. The original network splits into disjoint intranets. Two machines belong to the same intranet if and only if there is a path between them using only active links.

For example, in the left image above, only the links with priorities 66 and 55 are active, which creates two disjoint intranets. In the right example, three links are active, so all 44 machines form one intranet.

As part of the quality assurance team at Apricot Rules LLC, you are investigating how serious the problem is. Find the probability that there are exactly KK intranets when the priorities are assigned uniformly at random among all (M(M−1)/2)!(M(M-1)/2)! ways of doing so.

Input

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case is described in a single line containing two integers MM and KK: the number of machines and the target number of intranets, respectively.

Output

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the sought probability modulo the prime 109+710^9+7 (10000000071000000007). Represent the probability as an irreducible fraction p/qp/q, where pp and qq are non-negative integers that minimize p+qp+q. Then yy must equal p⋅q−1 mod (109+7)p \cdot q^{-1} \bmod (10^9+7), where q−1q^{-1} is the modular multiplicative inverse of qq with respect to the modulus 109+710^9+7. It can be shown that under the constraints of this problem, such a number yy always exists and is unique.

Constraints

  • 1≤T≤501 \le T \le 50.
  • 1≤K≤M/21 \le K \le M/2.

Hint

In Sample Case #1, consider the following situation. Let us call the M=5M=5 machines 1,2,3,4,51, 2, 3, 4, 5, and denote the link connecting machine aa and machine bb by (a,b)(a,b). Assume the priorities of links (1,2),(1,3),(1,4),(1,5),(2,3),(2,4),(2,5),(3,4),(3,5),(4,5)(1,2), (1,3), (1,4), (1,5), (2,3), (2,4), (2,5), (3,4), (3,5), (4,5) are 9,8,7,6,5,4,3,2,1,109, 8, 7, 6, 5, 4, 3, 2, 1, 10, respectively. Then machines 1 and 2 use link (1,2)(1,2), machine 3 uses link (1,3)(1,3), and machines 4 and 5 use link (4,5)(4,5). Thus three links (1,2),(1,3),(4,5)(1,2), (1,3), (4,5) are active, and there are two intranets {1,2,3}\{1,2,3\} and {4,5}\{4,5\}. Since K=2K=2, this situation counts toward the answer.

There are 15552001555200 ways to assign the priorities so that there are exactly 22 intranets, out of 10!=362880010!=3628800 ways, so the probability is 3/73/7. In Sample Case #2, the probability is 4/74/7. In Sample Case #3, the probability is 1/211/21.

Examples1

  1. Example 1

    Input
    3
    5 2
    5 1
    6 3
    
    Expected output
    Case #1: 428571432
    Case #2: 571428576
    Case #3: 47619048