def cnv(c):
    rm='ABCDEFGHI'
    id=[(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3)]
    return id[rm.index(c)]
 
while(1):
    n=int(raw_input())
    if n==0:
        break
    else:
        [s,t,b]=[cnv(c) for c in raw_input().split()]
        A=[[0 for i in range(5)] for j in range(5)]
        B=[[0 for i in range(5)] for j in range(5)]
        A[s[0]][s[1]]=1
        for i in range(n):
            for j in range(1,4):
                for k in range(1,4):
                    B[j][k]=(A[j+1][k]+A[j-1][k]+A[j][k+1]+A[j][k-1])*0.25
            B[b[0]][b[1]]=0 
            for j in range(1,4):
                A[j][1:4]=B[j][1:4]
        print A[t[0]][t[1]]