n,s,t,b;
double P[16][9];
main(){
	int i;
	for(;scanf("%d%s%s%s",&n,&s,&t,&b)*n;){
		memset(P,0,sizeof(P));
		P[n][s-'A']=1;
		for(;n--;){
			for(i=0;i<9;i++){
				P[n][i/3>0&&i-3!=b-'A'?i-3:i]+=P[n+1][i]/4;
				P[n][i/3<2&&i+3!=b-'A'?i+3:i]+=P[n+1][i]/4;
				P[n][i%3>0&&i-1!=b-'A'?i-1:i]+=P[n+1][i]/4;
				P[n][i%3<2&&i+1!=b-'A'?i+1:i]+=P[n+1][i]/4;
			}
		}
		printf("%f\n",P[0][t-'A']);
	}
}