### constant

N = 3
NN = N * N

DIRS = [[1, 0], [0, -1], [-1, 0], [0, 1]]

### main

ch2xy = {}
for y in (0...N)
  for x in (0...N)
    id = y * N + x
    ch2xy[('A'.ord + id).chr] = [x, y]
  end
end
#p ch2xy

zmtx = NN.times.map{0.0}

loop do
  n = gets.to_i
  break if n == 0

  s, t, b = gets.split

  sx, sy = ch2xy[s]
  tx, ty = ch2xy[t]
  bx, by = ch2xy[b]
  #p [sx, sy, tx, ty, bx, by]

  pmtx = zmtx.clone
  pmtx[sy * N + sx] = 1.0

  n.times do
    pmtx0 = pmtx
    pmtx = zmtx.clone

    for y in (0...N)
      for x in (0...N)
        for dir in DIRS
          x0 = x + dir[0]
          y0 = y + dir[1]
          if x0 >= 0 && x0 < N && y0 >= 0 && y0 < N && (x0 != bx || y0 != by)
            pmtx[y0 * N + x0] += pmtx0[y * N + x] * 0.25
          else
            pmtx[y * N + x] += pmtx0[y * N + x] * 0.25
          end
        end
      end
    end
  end

  printf("%.8f\n", pmtx[ty * N + tx])
end