This page is still under construction.

Parts of this page are still being built. What you see may change.

Clockwise Fence

Time limit1sMemory limit512 MB

Summary
For each of N closed fence paths given as N/E/S/W moves, decide whether the path runs clockwise or counterclockwise around the region it encloses.
Level

Medium4 of 10

Topics
Geometry, Implementation, Math
Solved
No attempts yet

Problem

The fence surrounding Farmer John's largest pasture has fallen into disrepair, and he has finally decided to replace it with a new fence.

Unfortunately, as Farmer John is laying out the new fence, a large bee ends up chasing him around the pasture, and as a result, the fence ends up following a rather irregular path. The fence can be described by a string of characters, each either "N" (north), "E" (east), "S" (south), or "W" (west). Each character describes a 1-meter run of the fence. For example, if the string is NESW, this means the fence starts by moving north for 1 meter, then east for 1 meter, then south for 1 meter, then west for 1 meter, returning to its starting point.

The fence ends at the position where it started, and this is the only point visited more than once by the path of the fence (and the starting point is only re-visited once, at the end). As a result, the fence does indeed enclose a single connected region of the grassy pasture, even though this region could have a rather strange shape.

Farmer John is curious if the path in which he laid the fence traveled clockwise (with the enclosed region on the right side of the fence as one walks along the path of the fence in the order specified by the string) or counter-clockwise (with the enclosed region on the left side of the fence).

Input

The first line of input contains an integer NN (1≤N≤201 \leq N \leq 20). Each of the next NN lines contains a string of length at least 4 and at most 100, describing a single fence path.

Output

For each of the NN fence paths described in the input, output a line containing either "CW" (clockwise) or "CCW" (counterclockwise).

Examples1

  1. Example 1

    Input
    2
    NESW
    WSSSEENWNEESSENNNNWWWS
    
    Expected output
    CW
    CCW