z = STDIN.read.split
n = z.shift.to_i
z.take(n).each do |s|
  x = s.each_char.map { |c| c.ord - 65 }.to_a
  s = x.shift
  r = x.inject([s, s, s, s]) do |a, t|
    v =
      if t < a[0] && t + 7 - a[0] <= 3
        7
      elsif t > a[0] && a[0] + 7 - t <= 3
        -7
      else 0
    end
    v += a[1] + (t - a[0])
    [t, v, [v, a[2]].min, [v, a[3]].max]
  end
  u = s <= 2 ? 7 : 6
  ans = (0 .. u).any? do |i|
    x = i * 7 + r[2]
    y = i * 7 + r[3]
    x >= 0 && y < 52
  end
  puts (ans ? "YES" : "NO")
end