#!/usr/bin/python

import os
import sys
import itertools

f = sys.stdin
d = {'A': (0,0), 'B': (0,1), 'C': (0,2),
     'D': (1,0), 'E': (1,1), 'F': (1,2),
     'G': (2,0), 'H': (2,1), 'I': (2,2)}

while True:
    n = int(f.readline().strip())
    if n==0: sys.exit()

    s,t,b = f.readline().split()

    dp = [dict([((j,k),0) for k in xrange(3) for j in xrange(3)]) for i in xrange(n+1)]
    dp[0][d[t]] = 1

    for i in xrange(1,n+1):
        for j in xrange(3):
            for k in xrange(3):
                # up
                x,y = max(0,j-1), k
                if d[b]==(x,y):
                    dp[i][(j,k)] += dp[i-1][(j,k)]
                else:
                    dp[i][(x,y)] += dp[i-1][(j,k)]

                # down
                x,y = min(j+1,2), k
                if d[b]==(x,y):
                    dp[i][(j,k)] += dp[i-1][(j,k)]
                else:
                    dp[i][(x,y)] += dp[i-1][(j,k)]

                # left
                x,y = j, max(0,k-1)
                if d[b]==(x,y):
                    dp[i][(j,k)] += dp[i-1][(j,k)]
                else:
                    dp[i][(x,y)] += dp[i-1][(j,k)]

                # right
                x,y = j, min(2, k+1)
                if d[b]==(x,y):
                    dp[i][(j,k)] += dp[i-1][(j,k)]
                else:
                    dp[i][(x,y)] += dp[i-1][(j,k)]

    print dp[n][d[s]]/4.**n