This page is still under construction.

Parts of this page are still being built. What you see may change.

Fired

Time limit1sMemory limit256 MB

Summary
Choose one employee to fire so the cascade of staff left with no managers saves at least C with the smallest excess, breaking ties by larger number.
Level

Medium6 of 10

Topics
Graph, BFS, Simulation
Solved
No attempts yet

Problem

Charlie is the head of HR at a large company. Every employee except the CEO reports to one or more people. Nobody reports to themselves, directly or indirectly.

This year's budget arrived and the salary line was cut by CC dollars. Charlie does not like firing people, so he wrote a program that automatically fires any employee left with nobody to report to. The program repeats until no employee other than the CEO is without a manager. It never fires the CEO automatically, even though the CEO reports to nobody.

Charlie will fire exactly one person by hand and let the program handle the rest. The total salary of everyone fired has to be at least CC dollars, and among the choices that reach CC it has to be as close to CC as possible. If several employees produce the same total, pick the one with the largest employee number. A CEO can be incompetent too, so Charlie may fire the CEO.

Input

The first line contains one integer TT, the number of test cases.

Each test case begins with a line containing two integers NN and CC, the number of employees and the amount to save.

The next NN lines describe employees 00 through N−1N-1 in order. The line for employee ii starts with the salary SiS_i and the number of people RiR_i that employee ii reports to, followed by RiR_i numbers EijE_{ij}, the employee numbers of those people.

  • 1≤T≤1001 \le T \le 100
  • 1≤N≤2001 \le N \le 200
  • 1≤C≤∑iSi1 \le C \le \sum_i S_i
  • 1≤Si≤1000001 \le S_i \le 100000
  • 0≤Ri<N0 \le R_i < N, and exactly one employee has Ri=0R_i = 0.
  • 0≤Eij<N0 \le E_{ij} < N

Output

For each test case, print on its own line the employee number of the person Charlie should fire.

Examples5

  1. Example 1

    Input
    2
    4 10
    4 1 3
    5 0
    4 2 1 3
    2 1 1
    4 6
    5 0
    4 1 3
    4 2 0 3
    2 1 0
    
    Expected output
    1
    3
    
  2. Example 2

    Input
    1
    1 5
    5 0
    
    Expected output
    0
    
  3. Example 3

    Input
    1
    6 12
    10 0
    1 1 0
    2 1 1
    3 1 2
    4 1 3
    5 1 4
    
    Expected output
    3
    
  4. Example 4

    Input
    1
    5 3
    7 0
    3 1 0
    3 1 0
    5 1 0
    3 1 0
    
    Expected output
    4
    
  5. Example 5

    Input
    1
    5 5
    1 0
    2 1 0
    3 1 1
    2 1 0
    3 1 3
    
    Expected output
    3