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 MBBanks 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:
Write a program that finds all the unsafe banks.
The first line contains the number of test cases T (1≤T≤100).
Each test case starts with a line containing two integers: the number of banks n (1≤n≤10) and limit (100≤limit≤1000), the minimum total assets a bank needs to stay safe.
The next n lines describe the banks with IDs 0 to n−1, in order. The first number on a line is the bank's balance, and the second number is k, the number of banks that borrowed money from this bank. Then k 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.
For each test case, print one line that starts with Case # x:, where x 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:.