#include <iostream>
#include <vector>
using namespace std;

typedef vector <int> VI;
typedef vector <VI> VVI;

const int dx[4] = { 0, 0, 1, -1 };
const int dy[4] = { 1, -1, 0, 0 };

int get_x( char c )
{
	if ( c == 'A' || c == 'D' || c == 'G' ) return 0;
	if ( c == 'B' || c == 'E' || c == 'H' ) return 1;
	if ( c == 'C' || c == 'F' || c == 'I' ) return 2;
	return -1;
}

int get_y( char c )
{
	if ( c == 'A' || c == 'B' || c == 'C' ) return 0;
	if ( c == 'D' || c == 'E' || c == 'F' ) return 1;
	if ( c == 'G' || c == 'H' || c == 'I' ) return 2;
	return -1;
}


int main( void )
{
	int n; char s, t, b;
	while ( 1 )
	{
		cin >> n;
		if ( n == 0 ) break;
		cin >> s >> t >> b;

		int sx, sy, gx, gy, ox, oy;
		sx = get_x( s ); sy = get_y( s );
		gx = get_x( t ); gy = get_y( t );
		ox = get_x( b ); oy = get_y( b );

		VVI prev( 3, VI(3,0) ), next;
		prev[sy][sx] = 1;
		for ( int lpc = 0; lpc < n; lpc++ )
		{
			next = VVI( 3, VI( 3, 0 ) );
			for ( int i = 0; i < 3; i++ ) for ( int j = 0; j < 3; j++ )
			{
				if ( i == oy && j == ox ) continue;
				int stop = 0;
				for ( int k = 0; k < 4; k++ )
				{
					int nx = j + dx[k];
					int ny = i + dy[k];
					if ( nx < 0 || nx >= 3 || ny < 0 || ny >= 3 )
					{
						stop++;
						continue;
					}
					else if ( nx == ox && ny == oy )
					{
						stop++;
						continue;
					}
					next[i][j] += prev[ny][nx];
				}
				if ( stop ) next[i][j] += prev[i][j] * stop;
			}
			prev = next;
		}

		int sum = 0;
		// for ( int i = 0; i < 3; i++ ) for ( int j = 0; j < 3; j++ ) sum += next[i][j];
		sum = 1; for ( int i = 0; i < n; i++ ) sum *= 4;

		double answer = (double)next[gy][gx] / (double)sum;

		cout.precision( 8 );
		cout.setf( ios::fixed );
		cout << answer << endl;
	}
	return 0;
}