#include <stdio.h>
int main(void){
	int d[] = { -5, -1, 1, 5 };
	int np, bp, tp, pp, i, j, k, n, x, y;
	char s, t, b;
	
	for(; scanf("%d %c %c %c", &n, &s, &t, &b), n; ){
		double pr[2][25] = {};
		np = ( ( s - 'A' ) / 3 + 1 ) * 5 + ( s - 'A' ) % 3 + 1;
		tp = ( ( t - 'A' ) / 3 + 1 ) * 5 + ( t - 'A' ) % 3 + 1;
		bp = ( ( b - 'A' ) / 3 + 1 ) * 5 + ( b - 'A' ) % 3 + 1;
		pr[n & 1][np] = 1.0;

		for( ; n--; ){
			for( i = 1; i < 4; i++ ){
				for( j = 1; j < 4; j++ ){
					pr[n & 1][i * 5 + j] = 0.0;
				}
			}
			for( i = 1; i < 4; i++ ){
				for( j = 1; j < 4; j++ ){
					pp = i * 5 + j;
					for( k = 0; k < 4; k++ ){
						np = pp + d[k];
						x = np % 5;
						y = np / 5;
						if( x < 1 || x > 3 || y < 1 || y > 3 || np == bp ){
							pr[n & 1][pp] += pr[~n & 1][pp] * 0.25;
						}
						else{
							pr[n & 1][np] += pr[~n & 1][pp] * 0.25;
						}
					}
				}
			}
		}
		printf("%f\n", pr[0][tp] );
	}
	return 0;
}