while(1):
    n=int(raw_input())
    if n==0:
        break
    else:
        [s,t,b]=raw_input().split()
        rm='ABCDEFGHI'
        nxt={}
        A={}
        B={}
        nxt["A"]='AABD'
        nxt["B"]='ABEC'
        nxt["C"]='CCBF'
        nxt["D"]='ADEG'
        nxt["E"]='BDHF'
        nxt["F"]='CEFI'
        nxt["G"]='GGDH'
        nxt["H"]='GHEI'
        nxt["I"]='IIHF'
        for r in rm:
            A[r]=0
            B[r]=0
        A[s]=1
        for i in range(n):
            for r in rm:
                B[r]=0
            for r in rm:
                for c in nxt[r]:
                    if c==b:
                        B[r]+= A[r]*0.25
                    else:
                        B[c]+= A[r]*0.25
            A=B.copy()
        print A[t]