Under construction

Still being built. Things may change

Segments Removal

Time limit4sMemory limit2048 MB

Summary
Remove segments on points 1 to x to maximize total score, where each removal gains weight times its exclusively covered points and pays its penalty.
Level

Hard8 of 10

Topics
Dynamic programming, Segment tree, Intervals
Solved
No attempts yet

Problem

Consider points 1,2,…,x1, 2, \ldots, x on a coordinate axis. You are given a collection of segments that start and end in these points. Each segment has weight and penalty associated with it.

Initially, you have a score of 00. You can make moves. In each move, you select a segment from the given collection, remove it from the collection, and your score decreases by the penalty associated with the segment. In return, your score increases by the weight of the segment multiplied by the number of points with integer coordinates such that, at this moment of time, this segment is the only segment in the collection that covers these points. A segment is considered to cover its endpoints.

The total score is the sum of scores for the moves you make. Find the maximum total score you can achieve.

Input

The first line contains an integer tt (1≤t≤2⋅1051 \le t \le 2 \cdot 10^5), the number of test cases. The test cases follow.

The first line of each test case contains two integers: the number of segments nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) and the maximum coordinate xx (1≤x≤5⋅1051 \le x \le 5 \cdot 10^5).

Next nn lines contain the description of segments. Each line contains four integers: the start ℓi\ell_i and end rir_i of the segment (1≤ℓi≤ri≤x1 \le \ell_i \le r_i \le x), its weight wiw_i (1≤wi≤1091 \le w_i \le 10^9) and penalty pip_i (1≤pi≤1091 \le p_i \le 10^9).

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5. The sum of xx over all test cases does not exceed 5⋅1055 \cdot 10^5.

Output

For each test case, print a line containing one integer: the maximum possible score you can achieve.

Examples1

  1. Example 1

    Input
    2
    3 8
    3 7 3 2
    5 8 2 1
    1 3 2 2
    2 5
    1 3 2 7
    3 5 3 4
    
    Expected output
    16
    2