Motorways
Time limit1sMemory limit128 MB
Assign each of k motorway chords to one of two sides so that no two chords on the same side interleave, choosing the lexicographically smallest assignment.
Statement
Byteotia lies on a peninsula. Ever since the reign of King Byteol, railways have been the main means of transport there. King Byteol had a super-speed railway line built that connects the western and eastern coasts of the peninsula. It runs through every town of Byteotia and so fixes their numbering: the first town on the line is town and the last is town . Town lies on the western coast and town on the eastern coast.

Fig. 1. The Byteotian railway line.
Thanks to minister Byterowicz the economy has grown quickly, and the transport network must be modernised. King Byteol has ordered motorways to be built. Each motorway directly joins two chosen towns. Because every motorway is built by a different agency with its own vignette, no motorway may cross another motorway or the railway line. The only way to achieve this is to build each motorway either to the north or to the south of the railway line, drawn as an arc between its two towns.

Fig. 2. A sample arrangement of the motorways joining towns 1-2, 1-3, 2-4, 5-7, 4-8, 7-8, 6-8 (arcs are dotted, the railway line is solid).
Two motorways placed on the same side of the railway cross exactly when their town intervals interleave: exactly one endpoint of one motorway lies strictly between the two endpoints of the other. Motorways that share a town, that are nested one inside the other, or that are completely separate never cross and may share a side. Motorways on opposite sides never cross.
King Byteol has already fixed which pairs of towns are to be joined. Decide, for every motorway, whether it goes to the north or to the south of the railway line so that no two motorways cross, or report that no such placement exists.
Input
The first line contains two integers and (): the number of towns and the number of planned motorways.
Each of the next lines contains two integers and (): the towns joined by the -th motorway. No pair of towns is repeated.
Output
If no valid placement exists, print a single line containing IMPOSSIBLE.
Otherwise print lines. The -th line contains one uppercase letter for the -th motorway (in input order): N if that motorway must be built to the north of the railway line, or S if to the south.
Several placements may be valid. Among all valid placements, print the lexicographically smallest one, reading the letters from top to bottom as a single string and treating N as smaller than S.