while (n = gets.chomp.to_i) != 0
  s,t,b = gets.chomp.split

  rooms = {
    [0,0] => {name: "A", value: 0}, 
    [0,1] => {name: "B", value: 0}, 
    [0,2] => {name: "C", value: 0}, 
    [1,0] => {name: "D", value: 0}, 
    [1,1] => {name: "E", value: 0}, 
    [1,2] => {name: "F", value: 0}, 
    [2,0] => {name: "G", value: 0}, 
    [2,1] => {name: "H", value: 0}, 
    [2,2] => {name: "I", value: 0}
  } 

  rooms.each_value{|room| room[:value] = 1 if room[:name] == s}
  rooms.delete_if{|k, v| v[:name] == b}

  n.times do |n|
    tmp = {
      [0,0] => 0, [0,1] => 0, [0,2] => 0,
      [1,0] => 0, [1,1] => 0, [1,2] => 0,
      [2,0] => 0, [2,1] => 0, [2,2] => 0
    }
    rooms.each do |k, v|
      if v[:value] != 0
        row = k[0]
        column = k[1]
        p = v[:value] / 4.0
        #up
        if rooms.has_key?([row-1, column])
          rooms[k][:value] -= p
          tmp[[row-1, column]] += p
        end
        #down
        if rooms.has_key?([row+1, column])
          rooms[k][:value] -= p
          tmp[[row+1, column]] += p
        end
        #left
        if rooms.has_key?([row, column-1])
          rooms[k][:value] -= p
          tmp[[row, column-1]] += p
        end
        #right
        if rooms.has_key?([row, column+1])
          rooms[k][:value] = p
          tmp[[row, column+1]] += p
        end
      end
    end
    rooms.each_key do |k|
      rooms[k][:value] = tmp[k]
    end
  end
  rooms.each_value do |v|
    puts v[:value] if v[:name] == t
  end
end