Windmill Animation

Time limit1sMemory limit128 MB

Summary
Simulate a line rotating counter-clockwise about a pivot point, switching pivot whenever the line hits another of the given points, and report the first S pivots. Repeat for each dataset.
Level

Medium5 of 10

Topics
Geometry, Simulation, Sorting, Math
Solved
No attempts yet

Problem

A windmill animation works as follows.

A set of points in the plane is given, no three of which are collinear. One of the points is chosen as the first pivot, and a line is drawn through it at some initial angle. The animation then rotates the line counter-clockwise about the pivot at a constant rate. As soon as the rotating line reaches another of the points, that point becomes the new pivot, and the rotation continues about it. (The line is undirected, so it reaches a point when its angle, taken modulo 180∘180^\circ, equals the direction from the current pivot toward that point.)

Given the set of points, the initial pivot, and the initial angle of the line, write a program that outputs the sequence of pivot points in the order they become the pivot. The rate of rotation does not affect the result; only the order in which points become pivots matters.

Input

The first line of input contains a single integer PP (1≤P≤10001 \le P \le 1000), the number of data sets. The data sets are processed identically and independently.

The first line of each data set contains three integers MM, SS, II and a floating-point value AA, separated by spaces. MM (3≤M≤203 \le M \le 20) is the number of points, SS (3≤S≤203 \le S \le 20) is the number of pivot points to output, and II (1≤I≤M1 \le I \le M) is the index of the initial pivot. AA (0≤A<1800 \le A < 180) is the angle, in degrees, by which the initial line is rotated counter-clockwise from horizontal.

The next MM lines give the points: the kk-th of these lines contains the XX and YY coordinates (floating-point values) of the point with index kk. No three points are collinear.

Output

For each data set, output a single line containing SS space-separated point indices: the points that become pivots, in order, starting with the first pivot after the initial one. (The initial pivot's index is not printed at the front, but it may appear later if it becomes a pivot again.)

Examples1

  1. Example 1

    Input
    2
    5 5 1 45
    -1 1
    1 1
    0 0
    -1 -2
    1 -2
    5 7 3 0
    -1 1
    1 1
    0 0
    -1 -2
    1 -2
    
    Expected output
    4 5 2 1 4
    2 4 3 5 1 3 2