This page is still under construction.

Parts of this page are still being built. What you see may change.

K closest planet pairs

Time limit2sMemory limit256 MB

Summary
Print the K smallest squared distances among all pairs of up to 50000 planar points per query.
Level

Medium7 of 10

Topics
Divide and conquer, Geometry, Heap
Solved
No attempts yet

Problem

You made up a universe. It is flat, and every planet in it is one point on the plane. One person lives on each planet, and those people are extremely clever and never die. The planets sit still, so nobody could visit anyone else, until the people rebuilt their own planets into rockets and started moving toward each other.

Watching to see who meets first got boring, so you loaded every planet's coordinates into your computer and looked for the two closest planets. That question is far too common. So you changed it. Take every pair of two different planets and find the KK shortest distances among those pairs.

Given the coordinates of the planets, write a program that prints those KK distances as squared distances. If two different pairs have the same distance, count each pair separately and print the value once per pair.

Input

The first line contains the number of queries TT. (1≤T≤101 \le T \le 10)

The first line of each query contains the number of planets NN and the number of pairs to find KK, separated by a space. (1≤N≤5×1041 \le N \le 5 \times 10^4, 1≤K≤41 \le K \le 4)

Each of the next NN lines contains the coordinates XiX_i and YiY_i of planet ii, separated by a space. (1≤Xi,Yi≤1061 \le X_i, Y_i \le 10^6)

All coordinates are integers. No two planets share the same coordinates, and the number of pairs of two different planets is always at least KK.

Output

Print one line per query. The line for query ii starts with case i: , followed by the KK smallest squared distances in non-decreasing order, separated by single spaces. Query numbers start at 1.

Examples2

  1. Example 1

    Input
    2
    5 1
    8 3
    13 11
    8 10
    17 18
    17 13
    10 3
    13 11
    3 2
    18 6
    3 4
    3 12
    19 3
    18 18
    2 18
    5 6
    16 8
    
    
    Expected output
    case 1: 20
    case 2: 4 8 8
    
  2. Example 2

    Input
    1
    4 4
    1 1
    1 2
    2 1
    2 2
    
    Expected output
    case 1: 1 1 1 1