Financial Tsunami

Given banks with balances and loans to each other, repeatedly mark as unsafe any bank whose total assets (balance plus loans from safe banks) fall below a limit, and list them in the order they fail.

Medium5SimulationGraphImplementationNo attempts yetTime limit10sMemory limit512 MB

Problem

Banks lend money to each other. In tough economic times, a bank that goes bankrupt may be unable to pay back its loans. A bank's total assets are its current balance plus its loans to other banks. The figure below shows five banks. Their current balances are 25, 125, 175, 75, and 181 million Ringgit Malaysia (RM), respectively. The directed edge from node 1 to node 2 means that bank 1 lends 40 million RM to bank 2.

If a bank's total assets are under a given limit limit, the bank is unsafe. An unsafe bank cannot return the money it borrowed, so the lender cannot count that loan in its total assets. As a result, the lender may also become unsafe if its total assets drop under the limit.

Unsafe banks are determined by this process:

  1. Compute the total assets of every bank that is not yet unsafe. A loan counts only if the borrower is not yet unsafe.
  2. Every bank whose total assets are under limit is decided unsafe at the same time. A bank whose total assets equal limit is safe.
  3. If no bank became unsafe in this step, stop. Otherwise, go back to step 1.

Write a program that finds all the unsafe banks.

Input

The first line contains the number of test cases TT (1T1001 \le T \le 100).

Each test case starts with a line containing two integers: the number of banks nn (1n101 \le n \le 10) and limit (100limit1000100 \le \text{limit} \le 1000), the minimum total assets a bank needs to stay safe.

The next nn lines describe the banks with IDs 00 to n1n-1, in order. The first number on a line is the bank's balance, and the second number is kk, the number of banks that borrowed money from this bank. Then kk pairs of numbers follow. Each pair describes one borrower: the first number is the borrower's ID and the second is the amount borrowed.

Balances and amounts are non-negative numbers and may contain a decimal point, as in 100.5. Compare total assets with limit exactly, without rounding.

Output

For each test case, print one line that starts with Case # x:, where xx is the test case number starting from 1. Right after the colon, print the IDs of the unsafe banks separated by single spaces.

Print the IDs in increasing order of the time at which each bank is decided unsafe. If several banks are decided unsafe at the same time, print their IDs in increasing order. If there is no unsafe bank, print only Case # x:.