// by Dan Joyce
// solves Problem 8: Slurpys 
// of 1996 Mid Atlantic programming contest

// input lists a bunch of character strings 
// output tells if the strings are slurpys 

import java.io.*;
import common.doinput; 

class problem8 {

  /* Character String stuff **************************************/

  static String charString;               // current character string
  static int CSLocation = 0;              // current location

  static char curChar() {
  // returns the current character of the current character string
  return charString.charAt(CSLocation);
  }

  static void consumeChar() {
  // consumes the current character
  if (offEndOfCharString()) 
    System.out.println ("Can not consume off the end of the string");
  else CSLocation++;
  }

  static boolean endOfCharString() {
  if (CSLocation == (charString.length() - 1))
     return true;
  else return false;
  }

  static boolean offEndOfCharString() {
  if (CSLocation == charString.length() )
     return true;
  else return false;
  }

  /* end of the character string stuff ****************************/

  static boolean isSlump() {
  // returns true if the next part of the current character string is a Slump

  // Slump starts with a D or E
  if (!((curChar() == 'D') || (curChar() == 'E'))) return false;

  if (endOfCharString()) return false;
  consumeChar();

  // followed by at least one F
  if (!(curChar() == 'F')) return false;

  if (endOfCharString()) return false;
  consumeChar();

  // or more than one F
  while (curChar() == 'F') {
    if (endOfCharString()) return false;
    consumeChar();
    };

  // ended by a G or another Slump
  if (curChar() == 'G') 
     {consumeChar();
      return true;
     }
  else return isSlump();
  }

  static boolean isSlimp() {
  // returns true if the next part of the current character string is a Slimp

  // Slimp starts with an A
  if (!(curChar() == 'A')) return false;

  if (endOfCharString()) return false;
  consumeChar();

  // followed by an H or a B + Slimp + C or a Slump + C
  // just the H
  if (curChar() == 'H') {consumeChar();
                       return true; 
                      }
  // the B + Slimp + C
  else if (curChar() == 'B')
         {if (endOfCharString()) return false;
          consumeChar();
          if (!isSlimp()) return false;
          if (offEndOfCharString()) return false;
          if (!(curChar() == 'C')) return false;
          consumeChar();
          return true;
         }

  // the Slump + C
  else {if (!isSlump()) return false;
        if (offEndOfCharString()) return false;
        if (!(curChar() == 'C')) return false;
        consumeChar();
        return true;
       }
  }        

  static boolean isSlurpy() {
  // returns true if the current character string is a slurpy

  if (!(isSlimp())) return false;
  if (offEndOfCharString()) return false;
  if (!(isSlump())) return false;
  if (!(offEndOfCharString())) return false;
  else return true;
  } 


  public static void main (String [] args) throws IOException {

    int N;                            // number of substrings
    doinput myinput = new doinput();

    System.out.println ("SLURPY OUTPUT");

    N = myinput.nextint();

    for (int count = 1; count <= N; count++)
      {
      charString = myinput.nextsubstring();
      CSLocation = 0;
      if ((isSlurpy()))
        System.out.println("YES");
      else System.out.println("NO");
      };

    System.out.println ("END OF OUTPUT");
  }
}

