#P11056. [2016杭电多校]Master Zhu

[2016杭电多校]Master Zhu

Master Zhu

Problem Description

Master Zhu has a NMN * M chess-board.In the Ith row,the squares from the LithL_ith column to the RithR_ith 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 chessmans he should place.

Input

There are multiple test cases. The first line of input contains an integer T, 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 column. For the next n 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 min minimum number of chessmans he should place.

Sample Input

3
3 3
1 1
2 2
3 3
2 4
1 3
2 4
3 2
1 2
1 2
1 2

Sample Output

3
2
2

Author

UESTC

Source

2016 Multi-University Training Contest 6