pos={"A":(0,0),"B":(1,0),"C":(2,0),"D":(0,1),"E":(1,1),"F":(2,1),
     "G":(0,2),"H":(1,2),"I":(2,2)}
mv=((0,1),(0,-1),(1,0),(-1,0))

def dfs(x,y,n):
    global prob
    if n==0:
        return 1.0 if (x,y)==t else 0.0
    for dx,dy in mv:
        mx=x+dx
        my=y+dy
        if mx<0 or mx>2 or my<0 or my>2 or (mx,my)==b:
            prob+=0.25*dfs(x,y,n-1)
        else:
            prob+=0.25*dfs(mx,my,n-1)
    return prob

while True:
    n=input()
    if n==0:break
    s,t,b=raw_input().split()
    s,t,b=pos[s],pos[t],pos[b]
    prob=0.0
    prob=dfs(s[0],s[1],n)
    print prob