$aryCheck = [[0],#dummny 
	[2,4], [1,3,5], [2,6], [1,5,7], [2,4,6,8], [3,5,9], [4,8], [5,7,9], [6,8]
]
def movecheck( p1, p2 )
	$aryCheck[ p1 ].include?( p2 )		
end

def checkpass( password ) 
	flag = true
	ary = password.split(//).map{|a| a.ord - "A".ord + 1}
	(ary.size - 1 ).times{ |i|
		unless movecheck( ary[ i ], ary[ i + 1 ])
			flag = false
			break	
		end
	}
	return flag
end

ans = Array.new
1000.times{
	line = $stdin.gets
	ans << line	if checkpass( line.chomp! )
}
ans.each{ |a| puts a }
