Slurpy

Decide whether each uppercase string is a Slurpy, meaning a Slimp immediately followed by a Slump, where both are defined by recursive grammar rules.

Medium5RecursionStringImplementationBacktrackingInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

A Slurpy is a string that satisfies the rules defined below. Write a program that reads strings and decides whether each one is a Slurpy.

First, a Slump is a string that satisfies these rules.

  1. The first character is 'D' or 'E'.
  2. One or more copies of 'F' follow the first character.
  3. After that run of 'F' comes either another Slump or the single character 'G'. A Slump therefore always ends with 'G'. For example, DFFEFFFG starts with 'D', continues with two copies of 'F', and then holds another Slump, EFFFG. The same rules show that EFFFG is a Slump.
  4. A string that these rules cannot build is not a Slump.

A Slimp is a string that satisfies these rules.

  1. The first character is 'A'.
  2. If the Slimp has length 2, the second character is 'H'.
  3. If the Slimp has length 3 or more, it has one of these two forms.
    1. 'A' + 'B' + Slimp + 'C'
    2. 'A' + Slump + 'C'
  4. A Slimp has length at least 2, and a string that these rules cannot build is not a Slimp.

A Slurpy is one Slimp followed by one Slump.

The classification works out like this.

  • Slumps: DFG, EFG, DFFFFFG, DFDFDFDFG, DFEFFFFFG
  • Not Slumps: DFEFF, EFAHG, DEFG, DG, EFFFFDG
  • Slimps: AH, ABAHC, ABABAHCC, ADFGC, ADFFFFGC, ABAEFGCC, ADFDFGC
  • Not Slimps: ABC, ABAH, DFGC, ABABAHC, SLIMP, ADGC
  • Slurpys: AHDFG, ADFGCDFFFFFG, ABAEFGCCDFEFFFFFG
  • Not Slurpys: AHDFGA, DFGAH, ABABCC

Input

The first line holds the number of strings NN, a positive integer no larger than 1010. Each of the next NN lines holds one string. Every string has length at most 6060 and consists of uppercase letters only.

Output

Print SLURPYS OUTPUT on the first line. Then, in input order, print one line per string: YES if the string is a Slurpy, NO if it is not. Print END OF OUTPUT on the last line.