欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF2148C.Pacer
Pacer
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 -th minute. Initially (at the start of the -th minute), FJ is at the starting side of the gym, which we will denote as side . The opposite side of the gym is denoted side .
The pacer test audio plays times. At the start of the -th minute, FJ must be at the -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
The first line contains an integer () — the number of test cases.
The first line of each test case contains two integers and () — the number of requirements and the number of total minutes.
The following lines contain two integers and — the -th requirement by the audio. It is guaranteed that over all .
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output the maximum number of points that FJ can acquire.
Note
For the first sample test case,
- During minute , FJ can stay at side .
- During minute , FJ can run to side and gain point.
- Right before minute , the audio requires FJ to be at side . Here, FJ is indeed at side .
- During minute , FJ can run to side and gain point.
- During minute , FJ can stay at side .
- Right before minute , the audio requires FJ to be at side . Here, FJ is indeed at side .
- Since the start of minute has reached, the Pacer Test ends. His total score is .
Relevant illustration of the statement:

Samples
3
2 4
2 1
4 0
2 7
1 1
4 0
4 9
1 0
2 0
6 1
9 0
2
7
6
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |