You are playing matchup Terran vs. Protoss in StarCraft II and the game came to elimination, which can be simplified to one-dimensional setting.
You have the army consisting of m bashees with upgraded hyperflight rotors, located at point 0 on a coordinate line. Your opponent has n buildings located on the positive half of the line. Each building is regarded as a segment.
Here are movement rules for banshees:
Next are the attack rules:
Finally, here are defense rules:
You are given the initial position in this game. What is the minimal time required to eliminate all Protoss buildings?
You will be given multiple test cases in this problem.
The first line contains a single integer t, the number of test cases. Then, you will be given t test cases in the format below.
The first line of each test case contains two integers n and m (1≤n≤2⋅105, 1≤m≤109): the number of remaining Protoss buildings and the number of your banshees. All your banshees are initially located at point 0 of the line.
Each of the following n lines contains four integers ℓ, r, h, s (0≤ℓ<r≤1012, 0<h≤106, 0≤s≤106): the left and right endpoints of the building, its hitpoints and its shields, respectively. You may assume that buildings don't overlap and are given in the order of increasing their ℓ coordinate.
The sum of n over all test cases is at most 2⋅105.
For each test case, output the only number on a separate line: the minimal time required to eliminate all Protoss buildings. Your answer would be considered correct if its absolute difference with the jury's answer is at most 10−4.