#P9945. [USACO21FEB] Clockwise Fence B

[USACO21FEB] Clockwise Fence B

Problem Description

The fence surrounding Farmer John’s largest pasture has broken, and he has finally decided to replace it with a new one.

Unfortunately, while Farmer John was building the new fence, a huge bee suddenly appeared and chased him around his pasture, causing the fence to be built along a rather irregular path. The fence can be represented by a string, where each character is one of N (north), E (east), S (south), W (west). Each character represents a 11-meter-long segment of fence. For example, if the string is NESW, this means the fence extends 11 meter north from the starting point, then 11 meter east, then 11 meter south, then 11 meter west, returning to the fence’s starting point.

The ending position of the fence is the same as the starting position, and this is the only position on the fence’s path that is reached multiple times (so the starting position is the only position that is visited again, at the end of the fence). As a result, the fence does enclose a connected region of the pasture, although this region may have a very strange shape.

Farmer John wants to know whether the path he built is clockwise (when walking along the fence in the order given by the string, the enclosed region is on the right) or counterclockwise (the enclosed region is on the left).

Input Format

The first line of input contains an integer NN (1N201 \le N \le 20). Each of the next NN lines contains a string of length at least 44 and at most 100100, describing a fence path.

Output Format

For each of the NN input fence paths, output one line: CW (clockwise) or CCW (counterclockwise).

2
NESW
WSSSEENWNEESSENNNNWWWS
CW
CCW

Hint

Sample Explanation 1

Below are the two fence paths, with @ marking the starting position:

*>*
^ v
@<*
  *<*<*<*
  v     ^
*<@     *
v       ^
* *>*>* *
v ^   v ^
* *<* * *
v   ^ v ^
*>*>* *>*

Translated by ChatGPT 5