NOI Contest Archive

Archive / 2020 / December 2020

Turing Baths

Medium · National Olympiad in Informatics Sri Lanka - December 2020

Mr. Turing (the computer scientist who helped allies win the second world war and proposed a universal model for computers) has a friend name Mr. Grinch, who has an obsession with personal hygiene. For the sake of this question, we will assume that Mr. Grinch has a limited number of activities.

Mr. Grinch has some weird personal rules. He would never apply conditioner without washing away shampoo. He would never leave the house without checking if he closed the shower and bathroom door. Even though his conditioner works for both wet and dry hair, he would never dry his hair with anything on it. It would also be quite stupid to try drying his hair with a towel under the shower.

His Shampoo and Conditioner bottles can hold enough for two usages each. While he can take his towel out of the bathroom to dry his hair, he doesn’t want to take shampoo or conditioner bottles outside and make a mess.

Mr. Turing will be given a sequence of actions. He has to figure out if that is something Mr. Grinch would do. To do that, he wants to write a computer program and he’s seeking your help to do it.

In the start, the person doing the actions is outside the bathroom. Both shampoo and conditioner bottles are filled and the shower is switched (stopped) off.

Input Format

The first line contains a single integer T, the number of test cases.
2T lines will follow, with 2 lines for each testcase.

Output Format

The output should have T lines, one line per testcase.

Constraints

Limits

Sample Input 0

3
9
GOFSOFDCG
6
GSOCFD
7
GSCOFDG

Sample Output 0

Y
Y
N 2

Sample Input 1

3
12
GOSGGCSDFSOG
12
GOSGGCSFDSOG
18
GOSGGCSFDGAGSOCCFD

Sample Output 1

N 7
N 9
N 15