Recognizing strings based on a set of restrictions is a common computational problem. A Slurpy is a string of characters that has certain properties. Your program reads strings of characters and outputs whether or not each one is a Slurpy.
A Slump is a character string with the following properties:
D or an E.Fs.Fs is followed by either a Slump or a G. The Slump or G that follows the Fs ends the Slump. For example, DFFEFFFG is a Slump: it starts with a D, followed by two Fs, and is ended by the Slump EFFFG.A Slimp is a character string with the following properties:
A.H.A followed by B followed by a Slimp followed by a C.A followed by a Slump (see above) followed by a C.A Slurpy is a character string that consists of a Slimp followed by a Slump.
Examples
DFG, EFG, DFFFFFG, DFDFDFDFG, DFEFFFFFGDFEFF, EFAHG, DEFG, DG, EFFFFDGAH, ABAHC, ABABAHCC, ADFGC, ADFFFFGC, ABAEFGCC, ADFDFGCABC, ABAH, DFGC, ABABAHC, SLIMP, ADGCAHDFG, ADFGCDFFFFFG, ABAEFGCCDFEFFFFFGAHDFGA, DFGAH, ABABCCThe first line contains an integer $N$ ($1 \le N \le 10$), the number of strings. Each of the next $N$ lines contains a string of 1 to 60 alphabetic characters.
For each of the $N$ input strings, output YES or NO on its own line, indicating whether the corresponding string is a Slurpy.