var
  inp, oup : text;
  fl : array[1..100000] of boolean;
  s : string;
  i, n, j, sum : longint;
begin
  assign(inp, 'abbaa.in');
  assign(oup, 'abbaa.out');
  reset(inp);
  rewrite(oup);
  readln(inp, n);
  assert(1 <= n);
  sum := 0;
  for j := 1 to n do
    begin
      readln(inp, s);
      assert(length(s) >= 1);

      fl[1] := s[1] = 'A';
      fl[2] := (s[2] = 'A') or ((s[2] <> s[1]));
      inc(sum, length(s));
      for i := 3 to length(s) do
        fl[i] := ((s[i] = 'A') and (fl[i - 1])) 
        or ((fl[i - 2]) and (s[i - 1] <> s[i]));
      if fl[length(s)] then writeln(oup, 'YES') else writeln(oup, 'NO');
   end;
  assert(1 <= sum);
  assert(sum <= 100000);
  close(inp);
  close(oup);
end.
