Twirling Towards Freedom (Large)

Each minute you stay put or rotate 90 degrees clockwise around a star, and must report the largest squared distance from the origin reachable in M minutes.

Hard9GeometryNumber theoryBFSGreedyNo attempts yetTime limit5sMemory limit512 MB

Problem

Your spaceship starts at the origin (0,0)(0, 0) of a two-dimensional plane. The galaxy holds NN stars, and star ii is at (Xi,Yi)(X_i, Y_i).

Each minute you do exactly one of two things: pick a star and rotate the ship 90 degrees clockwise around that star, or stay where you are. You may pick the same star again later. Rotating a point (p,q)(p, q) by 90 degrees clockwise around (a,b)(a, b) moves it to (a+qb, bp+a)(a + q - b,\ b - p + a).

You have MM minutes, and you want to finish as far from the origin as possible. A rotation sends integer coordinates to integer coordinates, so the squared distance between the origin and the final position is always an integer. Report that integer.

The picture shows the first three rotations of one possible path. The yellow dots are stars and the purple dots are positions of the ship. This path is not necessarily part of an optimal solution.

Input

The first line has the number of test cases TT. The test cases follow. The first line of a test case has NN, the second line has MM, and each of the next NN lines has two integers XiX_i and YiY_i, the position of one star.

Limits

  • 1T1001 \le T \le 100
  • 1N10001 \le N \le 1000
  • 1000Xi1000-1000 \le X_i \le 1000
  • 1000Yi1000-1000 \le Y_i \le 1000
  • 1M1061 \le M \le 10^6
  • No two stars are at the same location.
  • A star may be at the origin.

Output

For each test case, print one line in the form Case #x: S, where xx is the test case number starting from 1 and SS is the square of the largest distance from the origin that the ship can reach within MM minutes. SS fits in a signed 64-bit integer.