TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM = *0...6

Direction = [
  [0, 1, 2, 3, 4, 5],
  [0, 2, 4, 1, 3, 5],
  [0, 4, 3, 2, 1, 5],
  [0, 3, 1, 4, 2, 5],
  [1, 5, 2, 3, 0, 4],
  [1, 3, 5, 0, 2, 4],
  [2, 5, 4, 1, 0, 3],
  [3, 4, 5, 0, 1, 2],
  [4, 0, 2, 3, 5, 1],
  [4, 2, 5, 0, 3, 1],
  [4, 5, 3, 2, 0, 1],
  [4, 3, 0, 5, 2, 1],
  [5, 4, 2, 3, 1, 0],
  [5, 2, 1, 4, 3, 0],
  [5, 1, 3, 2, 4, 0],
  [5, 3, 4, 1, 2, 0],
  [1, 2, 0, 5, 3, 4],
  [1, 0, 3, 2, 5, 4],
  [2, 1, 5, 0, 4, 3],
  [2, 4, 0, 5, 1, 3],
  [2, 0, 1, 4, 5, 3],
  [3, 1, 0, 5, 4, 2],
  [3, 0, 4, 1, 5, 2],
  [3, 5, 1, 4, 0, 2],
]

Connect = [
  [],
  [nil, nil, nil, [0, RIGHT], nil, nil],
  [nil, nil, nil, nil, [0, FRONT], nil],
  [nil, nil, nil, [2, RIGHT], [1, FRONT], nil],
  [[0, BOTTOM], nil, nil, nil, nil, nil],
  [[1, BOTTOM], nil, nil, [4, RIGHT], nil, nil],
  [[2, BOTTOM], nil, nil, nil, [4, FRONT], nil],
  [[3, BOTTOM], nil, nil, [6, RIGHT], [5, FRONT], nil],
]

def dfs(result, result_direction)
  return true if result.size == 8
  position = result.size
  8.times do |die|
    next if result.include?(die)
    Direction.each do |dir|
      ok = true
      6.times do |i|
        next unless Connect[position][i]
        id, face = Connect[position][i]
        a, b = @die[die][dir[i]], @die[result[id]][result_direction[id][face]]
        if a == b || a.downcase != b.downcase
          ok = false
          break
        end
      end
      if ok
        return true if dfs(result + [die], result_direction + [dir])
      end
    end
  end
  false
end

def check?
  Direction[0...8].each do |d|
    return true if dfs([0], [d])
  end
  false
end

until (list = [gets.chomp]) == ["0"]
  list += 7.times.map{gets.chomp}
  @die = list.map{|l| l.chars}
  puts check? ? "YES" : "NO"
end