#Lutece1455. Master Zhu

Master Zhu

Migrated from Lutece 1455 Master Zhu

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Master Zhu has an N×MN\times M chessboard. In the ii-th row, the squares from the LiL_i-th column to the RiR_i-th column is colored by black, and others are colored by white. Besides, it guarantees that LiLi+1,RiRi+1L_i\le L_{i+1},R_i\le R_{i+1}. Now Master Zhu is going to place some chessmans on serval black square, so that for each black square there are at least one chessman in its row or its column. Then he ask you the minimum number of chessmen he should place.

Input

There are multiple test cases. The first line of input contains an integer TT, indicating the number of test cases.

For each test case, the first line contains two integers nn and mm (1n,m100)(1\le n,m\le 100) -- the number of rows and columns. For the next nn lines, each line two integers Li,Ri(1LiRim)L_i,R_i(1\le L_i\le R_i\le m).

Output

For each test case, output the minimum number of chessmen he should place.

Samples

3

3 3
1 1
2 2
3 3

2 4
1 3
2 4

3 2
1 2
1 2
1 2
3
2
2

Resources

2016 Multi-University Training Contest 6