Football Team (Large)

No attempts yetTime limit5sMemory limit512 MB

Problem

A football team lines up in rows for a photograph. The position of each player is given by two integers xx and yy. Here yy is the number of the row the player stands in, and xx is the distance from the left edge of that row to the player. All xx values are different.

To make the photograph more interesting, players who stand near each other wear shirts of different colors. The rule is the following. For each player PP:

  • If the same row holds a closest player to the right of PP, that player must have a different shirt color.
  • If the previous row, meaning row y1y-1, holds a closest player to the right of PP, that player must have a different shirt color.
  • If the next row, meaning row y+1y+1, holds a closest player to the right of PP, that player must have a different shirt color.

More formally, if there is a player at (x1,y1)(x_1, y_1) and a player at (x2,y2)(x_2, y_2) with x1<x2x_1 < x_2, the two players must have different shirt colors when both of these hold:

  • y11y2y1+1y_1 - 1 \le y_2 \le y_1 + 1
  • no x3x_3 satisfies x1<x3<x2x_1 < x_3 < x_2 with a player standing at (x3,y2)(x_3, y_2)

Find the minimum number of distinct shirt colors that makes this possible.

Input

The first line contains one integer TT, the number of test cases. Each test case starts with a line holding one integer NN, the number of players, followed by NN lines that each give the position of one player in this format.

x y

Limits

  • 1T1001 \le T \le 100
  • 1x10001 \le x \le 1000
  • All xx values are different.
  • 1y301 \le y \le 30
  • 1N10001 \le N \le 1000

Output

For each test case, print one line in this format.

Case #X: c

XX is the test case number, starting from 1, and cc is the minimum number of colors required.