#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define EACH( it, c ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const int dir[][2] = {
	1, 0,
	0, 1,
	-1, 0,
	0, -1
};

PII c2idx( char c )
{
	int n = c - 'A';
	return MP( n / 3, n % 3 );
}

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );
	cout.precision( 7 );
	cout << fixed;

	while ( true )
	{
		int n;
		cin >> n;
		if ( !n )
		{
			break;
		}
		
		char s_, t_, b_;
		cin >> s_ >> t_ >> b_;
		
		PII s = c2idx( s_ ), t = c2idx( t_ ), b = c2idx( b_ );

		vector< vector< vector<double> > > dp( n + 1, vector< vector<double> >( 3, vector<double>( 3, 0 ) ) );
		dp[0][ s.fst ][ s.snd ] = 1;

		REP( t, 0, n )
		{
			REP( i, 0, 3 )
			{
				REP( j, 0, 3 )
				{
					REP( d, 0, 4 )
					{
						int di = i + dir[d][0], dj = j + dir[d][1];

						if ( !( 0 <= di && di < 3 && 0 <= dj && dj < 3 ) || MP( di, dj ) == b )
						{
							dp[ t + 1 ][i][j] += dp[t][i][j] / 4;
						}
						else
						{
							dp[ t + 1 ][ di ][ dj ] += dp[t][i][j] / 4;
						}
					}
				}
			}
		}

		cout << dp.back()[ t.fst ][ t.snd ] << endl;
	}

	return 0;
}