#include <stdio.h>
#include <string.h>

int first_x,first_y;
int zyuden_x,zyuden_y;
int soko_x,soko_y;
double map[16][3][3];

void get_where(int* x,int* y,char c) {
	if(c=='A'){*x=0;*y=0;}
	if(c=='B'){*x=1;*y=0;}
	if(c=='C'){*x=2;*y=0;}
	if(c=='D'){*x=0;*y=1;}
	if(c=='E'){*x=1;*y=1;}
	if(c=='F'){*x=2;*y=1;}
	if(c=='G'){*x=0;*y=2;}
	if(c=='H'){*x=1;*y=2;}
	if(c=='I'){*x=2;*y=2;}
}

int canmove(int x,int y) {
	if(x<0 || x>=3 || y<0 || y>=3)return 0;
	if(x==soko_x && y==soko_y)return 0;
	return 1;
}

int main(void) {
	int battery;
	char first[2],zyuden[2],soko[2];
	int i,j,k;
	while(1) {
		scanf("%d",&battery);
		if(battery==0)break;
		scanf("%s%s%s",first,zyuden,soko);
		get_where(&first_x,&first_y,first[0]);
		get_where(&zyuden_x,&zyuden_y,zyuden[0]);
		get_where(&soko_x,&soko_y,soko[0]);
		memset(map,0,sizeof(map));
		map[0][first_x][first_y]=1;
		for(i=0;i<battery;i++) {
			for(j=0;j<3;j++) {
				for(k=0;k<3;k++) {
					if(canmove(j-1,k))map[i+1][j-1][k]+=map[i][j][k]/4;
					else map[i+1][j][k]+=map[i][j][k]/4;
					if(canmove(j+1,k))map[i+1][j+1][k]+=map[i][j][k]/4;
					else map[i+1][j][k]+=map[i][j][k]/4;
					if(canmove(j,k-1))map[i+1][j][k-1]+=map[i][j][k]/4;
					else map[i+1][j][k]+=map[i][j][k]/4;
					if(canmove(j,k+1))map[i+1][j][k+1]+=map[i][j][k]/4;
					else map[i+1][j][k]+=map[i][j][k]/4;
				}
			}
		}
		printf("%.15f\n",map[battery][zyuden_x][zyuden_y]);
	}
	return 0;
}