Preventing Paradoxes

Interview

Time limit1sMemory limit128 MB

Summary
Given the vertices of a simple polygon in order, decide whether the traversal orientation is clockwise or counterclockwise.
Level

Medium4 of 10

Topics
Geometry, Implementation
Solved
No attempts yet

Problem

Time traveling runs the risk of causing all sorts of problems and paradoxes—duplicate people, parallel universes, and black holes, to name a few. Tim is well aware of what's at stake, but he keeps time traveling because he knows the secret: you have to properly close the tears in the space-time continuum! You do this simply by visiting each space-time destination in a right-handed (that is, clockwise) orientation.

Tim has a list of points in the space-time plane that describe his trip, and he must start and end at the same point. There are two ways to traverse the list: forwards and backwards. One way leads to prosperity, the other to paradoxes and total ruin. Write a program that, following the points in the given input order, decides whether Tim's right hand would be touching the interior of the polygon.

Input

The first line contains the number KK of data sets. It is followed by KK data sets, each of the following form.

The first line of each data set contains the number NN (3≤N≤1003 \le N \le 100) of space-time points in Tim's trip. Each of the next NN lines contains two integers ss and tt, a space-time coordinate, where ss is plotted on the x-axis and tt on the y-axis, with −100≤s,t≤100-100 \le s, t \le 100. Taken in order, the NN points always form a closed, non-self-intersecting polygon, and no three consecutive points are collinear.

Output

For each data set, first print Data Set x: on a line by itself, where xx is its number. On the next line, print RIGHT if, looking down on the space-time plane, Tim's right hand would touch the interior of the polygon as he traverses the points in input order; otherwise print LEFT. Separate consecutive data sets with a blank line.

Examples1

  1. Example 1

    Input
    2
    5
    3 0
    4 1
    5 0
    5 3
    2 2
    3
    0 1
    2 2
    1 0
    
    Expected output
    Data Set 1:
    LEFT
    
    Data Set 2:
    RIGHT