Slurpys

No attempts yetTime limit1sMemory limit128 MB

Problem

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:

  1. Its first character is either a D or an E.
  2. That first character is followed by a string of one or more Fs.
  3. The string of one or more 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.
  4. Nothing else is a Slump.

A Slimp is a character string with the following properties:

  1. Its first character is an A.
  2. If it is a two-character Slimp, then its second and last character is an H.
  3. If it is not a two-character Slimp, then it has one of these two forms:
    • A followed by B followed by a Slimp followed by a C.
    • A followed by a Slump (see above) followed by a C.
  4. Nothing else is a Slimp.

A Slurpy is a character string that consists of a Slimp followed by a Slump.

Examples

  • 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 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.

Output

For each of the $N$ input strings, output YES or NO on its own line, indicating whether the corresponding string is a Slurpy.