This page is still under construction.

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

Herding Sheep

Time limit2sMemory limit256 MB

Summary
Assign every sheep to a barn holding at most K sheep to minimize the longest walk, and print the squared optimum.
Level

Medium6 of 10

Topics
Binary search, Graph
Solved
No attempts yet

Problem

Elly and her herd of sheep are in trouble again. After a whole day of grazing the sheep have to go into the barns so that they are safe for the night. One barn holds at most KK sheep. A barn does not have to be full and may stay empty. All that matters is that every sheep ends up inside some barn.

To keep things simple, the sheep are NN points and the barns are MM points with integer coordinates on the plane. Several sheep may share the same coordinates, several barns may share the same coordinates, and a sheep and a barn may share the same coordinates.

A sheep walks one unit of distance per second. A sheep at (0,0)(0, 0) that walks to a barn at (1,3)(1, 3) needs about 3.16227766 seconds, and a barn at (3,4)(3, 4) takes exactly 5 seconds. All sheep move at the same time and never block each other.

Compute the minimum time needed for all sheep to be inside barns. In other words, minimize the largest walking time over all sheep.

Input

The first line contains one integer TT, the number of test cases.

Each test case begins with three integers NN, MM and KK: the number of sheep, the number of barns, and the maximum number of sheep in one barn.

The next NN lines each contain two integers XX and YY, the coordinates of a sheep.

The next MM lines each contain two integers XX and YY, the coordinates of a barn.

  • 1≤T≤201 \le T \le 20
  • 1≤N,M,K≤2001 \le N, M, K \le 200
  • −1000≤X,Y≤1000-1000 \le X, Y \le 1000
  • N≤M×KN \le M \times K

Output

For each test case, print the square of the minimum time as an integer on its own line. All coordinates are integers, so the square of the minimum time is always an integer. If the minimum time is 5 seconds, print 25.

Examples5

  1. Example 1

    Input
    2
    5 3 2
    2 13
    9 6
    4 8
    13 7
    11 3
    2 11
    10 6
    4 12
    7 3 3
    -959 -542
    -669 -513
    160 717
    473 344
    -51 -548
    703 -869
    270 -181
    957 -509
    -6 937
    -175 434
    
    Expected output
    61
    1567232
    
  2. Example 2

    Input
    1
    1 1 1
    0 0
    0 0
    
    Expected output
    0
    
  3. Example 3

    Input
    1
    2 2 1
    0 0
    0 1
    0 1
    0 10
    
    Expected output
    81
    
  4. Example 4

    Input
    1
    5 2 3
    0 0
    0 0
    0 0
    0 0
    0 0
    0 0
    3 4
    
    Expected output
    25
    
  5. Example 5

    Input
    2
    1 1 1
    -1000 -1000
    1000 1000
    2 2 1
    -1000 1000
    1000 -1000
    1000 1000
    -1000 -1000
    
    Expected output
    8000000
    4000000