while gets
	n = $_.to_i
	break if n == 0
	s, t, b = gets.split
	rm = { "A"=>["B","D"],      "B"=>["A","C","E"],      "C"=>["B","F"],
           "D"=>["A","E","G"],  "E"=>["D","B","F","H"],  "F"=>["E","C","I"],
           "G"=>["H","D"],      "H"=>["E","G","I"],      "I"=>["F","H"]}                 
  	rm.each_key{|k|
        rm[k].select!{|item| item != b}
  	}
  	prob = [Hash.new(0.0), Hash.new(0.0)]
  	prob[0][s] = 1.0
  	i = 0
  	n.times do 
  		rm.each{|k,v|
  			prob[1-i][k] = ((4.0 - v.size)/4) * prob[i][k]
  			v.each{|r|
  				prob[1-i][k] += prob[i][r] / 4
  			}
  		}
  		i = 1-i
  	end
	p prob[i][t]
end 