Mountainous landscape
Time limit10sMemory limit256 MB
For each segment of a left-to-right polygonal chain, find the nearest later segment with a point strictly above the ray extending the segment.
Problem
You travel through a landscape made mostly of mountains. There are landmarks, peaks and valleys, along your path. You stop to catch your breath and wonder which mountain you are looking at on the horizon.
Stated formally: you are given a polygonal chain in the plane, and the coordinates of the points are strictly increasing. For each segment of the chain, find the smallest index such that some point of lies strictly above the ray that starts at and passes through .
A point lies strictly above the ray when and .
Input
The first line contains the number of test cases . The test cases follow one after another.
The first line of each test case contains the number of vertices of the chain, ().
Each of the next lines contains the integer coordinates and of vertex (, ).
Output
For each test case, print one line with space separated integers. The -th number is the smallest index of a chain segment visible to the right of segment , or 0 when no such segment exists.