Limits 1s, 512 MB

Little Bunny loves to eat corns. Fortunately, he lives near an abandoned house which has a huge cornfield in the backyard. For some weird reason, all the corn plants are in a single row. Each plant has only one corn. Each corn has two important properties, length and quality.

Winter is coming and it’s time for him to collect the corns. Otherwise he will starve to death. Little Bunny has its own way to collect corns. There will be N corn plants. Little Bunny will start collecting the corns from 1 to N. Note that he can’t jump to a corn plant without collecting all the corns before it. Before collecting the corns he will grab a box. After picking a corn he can put it into the box if the box is empty or it fulfills all the following conditions.

After putting the corn into the box:

  1. The length of all corns must remain same.
  2. The quality of the corns remain either in increasing or decreasing order.
  3. The difference between any pair of adjacent corns’ quality must remain same.
    Remember that Little Bunny does not change the order of the corns when putting them into the box. At some point, if Little Bunny fails to put the corn into the box he will pack the current box and then pick a new box to put the current corn into it.
    After finishing, collecting and packing the corns, Little Bunny will gather all the boxes in a same place. He doesn’t like boxes having less than 3 corns and will dump them on the field. He wants to know how many boxes are there at the end.

Input

Input will start with a positive integer TT (T50T ≤ 50) denoting the number of test cases. Each test case will start with a positive integer NN (3N1003 ≤ N ≤ 100) denoting the number of corn plants. Each of the following NN lines will have two integers LiL_i, QiQ_i denoting the length and the quality of the ii-th corn, where 1Li10001 ≤ L_i ≤ 1000 and QiQ_i will fit into a 32-bit signed integer.

Output

For each test case please output the answer as the following format, “Case t: b” without the quotations. Here tt is the case number and bb is the number of boxes of corns Little Bunny has at the end.

Sample

InputOutput
2
6
1 0
1 1
1 2
1 1
1 0
2 0
6
1 1
1 2
1 3
2 4
2 3
2 2
Case 1: 1
Case 2: 2

Submit

Login to submit.

Statistics

71% Solution Ratio
DayDreamerEarliest, Apr '18
BrownbearFastest, 0.0s
ankonashLightest, 0 B
tahsin_protikShortest, 657B
Toph uses cookies. By continuing you agree to our Cookie Policy.