Lighthouses

All submissions for this problem are available.
Read problems statements in Mandarin and Russian. Translations in Vietnamese to be uploaded soon.
There are N islands in the sea, enumerated from 1 to N. Each of them is so small that we can consider them as points on a plane. You are given the Cartesian coordinates of all islands. Xaxis is directed towards East and Yaxis is directed towards North.
You need to illuminate all the islands. To do this, you can place lighthouses on some of the islands. You can't place more than one lighthouse on any single island. Each lighthouse can light only one of the 4 quadrants: NorthWestern, NorthEastern, SouthWestern or SouthEastern. If some island is located on the border of an illuminated quadrant, it is considered to be illuminated as well. Note that this means that a lighthouse always illuminates it's own island as well.
Find the smallest possible number of lighthouses required to illuminate all the islands (say L). Describe their configurations — positions and quadrants illuminated — as well.
Input
The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of islands.
The i^{th} of the following N lines contains two integers X_{i} and Y_{i} denoting the coordinates of the i^{th} island.
Output
For each test case, first line of output must contain minimum number of lighthouses required to illuminate all islands, L.
Following L lines must describe configuration of the lighthouses, one configuration per line. Description of a lighthouse configuration consists of the number of the island where the lighthouse is placed, and the direction of the quadrant (NW for NorthWestern, NE for NorthEastern, SW for SouthWestern, SE for SouthEastern) illuminated by it, separated by a single space.
If there are many possible placements, output any one of them.
Constraints
 1 ≤ T ≤ 1000
 1 ≤ N ≤ 10^{5}
 The sum of N over all test cases doesn't exceed 5*10^{5}
 Absolute value of each coordinate doesn't exceed 10^{9}
 No two given islands coincide.
Subtasks
Subtask 1: (15 points)
 1 ≤ N ≤ 8
 Absolute value of each coordinate doesn't exceed 50
Subtask 2: (85 points)
 Original constraints
Example
Input: 2 5 0 0 1 0 2 0 0 1 0 2 4 5 0 5 0 0 5 0 5 Output: 1 3 SW 2 4 NE 2 NE
Explanation
Example case 1. Also we can place lighthouse on 1^{st} or 5^{th} island.
Example case 2. Notice that some islands can be illuminated by more than 1 lighthouse.
Author:  eartemov 
Tester:  kevinsogo 
Editorial  http://discuss.codechef.com/problems/LIGHTHSE 
Tags  adhoc, eartemov, easymedium, sept15 
Date Added:  23072015 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 