CF2148C Pacer

Description

The FitnessGram Pacer Test is a multistage aerobic capacity test that progressively gets more difficult as it continues. The 20 meter pacer test will begin in 30 seconds. Line up at the start. A single lap should be completed every time you hear this sound. Ding! Remember to run in a straight line and run as long as possible. The test will begin on the word start. On your mark. Get ready!... Farmer John is running the FitnessGram Pacer Test! Farmer John takes one minute to run to the other side of the gym. Therefore, at the start of each minute, FJ can choose to either run to the other side of the gym or stay in place. If he chooses to run to the other side of the gym, he gains one point. FJ will run the Pacer Test until the start of the $ m $ -th minute. Initially (at the start of the $ 0 $ -th minute), FJ is at the starting side of the gym, which we will denote as side $ 0 $ . The opposite side of the gym is denoted side $ 1 $ . The pacer test audio plays $ n $ times. At the start of the $ a_i $ -th minute, FJ must be at the $ b_i $ -th side of the gym. What is the maximum number of points FJ can acquire while ensuring that he meets the audio's requirements?

Input Format

The first line contains an integer $ t $ ( $ 1 \leq t \leq 10^4 $ ) — the number of test cases. The first line of each test case contains two integers $ n $ and $ m $ ( $ 1 \leq n \leq 2 \cdot 10^5, n \leq m \leq 10^9 $ ) — the number of requirements and the number of total minutes. The following $ n $ lines contain two integers $ a_i $ and $ b_i $ $ (1 \leq a_i \leq m, b_i \in \{0,1\}) $ — the $ i $ -th requirement by the audio. It is guaranteed that $ a_i > a_{i-1} $ over all $ i > 1 $ . It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2 \cdot 10^5 $ .

Output Format

For each test case, output the maximum number of points that FJ can acquire.

Explanation/Hint

For the first sample test case, - During minute $ 0 $ , FJ can stay at side $ 0 $ . - During minute $ 1 $ , FJ can run to side $ 1 $ and gain $ 1 $ point. - Right before minute $ 2 $ , the audio requires FJ to be at side $ 1 $ . Here, FJ is indeed at side $ 1 $ . - During minute $ 2 $ , FJ can run to side $ 0 $ and gain $ 1 $ point. - During minute $ 3 $ , FJ can stay at side $ 0 $ . - Right before minute $ 4 $ , the audio requires FJ to be at side $ 0 $ . Here, FJ is indeed at side $ 0 $ . - Since the start of minute $ 4 $ has reached, the Pacer Test ends. His total score is $ 2 $ . Relevant illustration of the statement: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF2148C/2169f5238c3a502916872db9cb4225dd65855e139ecbfe9a49d444ac4f53cc8f.png)