#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;
struct Point
{
	int x;
	int y;
	Point(){};
	Point(int a, int b)
	{
		x = a;
		y = b;
	}
};
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };
double dp[17][3][3];
char stage[3][3];

void solve()
{
	int n;
	while (cin >> n, n)
	{
		char s, t, b;
		cin >> s >> t >> b;
		Point start, goal, warehouse;
		start.x = (s - 'A') % 3;
		start.y = (s - 'A') / 3;
		goal.x = (t - 'A') % 3;
		goal.y = (t - 'A') / 3;
		warehouse.x = (b - 'A') % 3;
		warehouse.y = (b - 'A') / 3;
		fill(dp[0][0], dp[0][0] + 3 * 3 * 17, 0.0);
		dp[0][start.y][start.x] = 1.0;
		for (int i = 0; i < n; ++i)
		{
			for (int y = 0; y < 3; ++y)
			{
				for (int x = 0; x < 3; ++x)
				{
					for (int j = 0; j < 4; ++j)
					{
						int nx = x + dx[j];
						int ny = y + dy[j];
						if ((nx < 0 || nx >= 3 || ny < 0 || ny >= 3) || (nx == warehouse.x && ny == warehouse.y))
						{
							dp[i + 1][y][x] += dp[i][y][x] / 4.0;
						}
						else
						{
							dp[i + 1][ny][nx] += dp[i][y][x] / 4.0;
						}
					}
				}
			}
		}
		printf("%.7f\n", dp[n][goal.y][goal.x]);
	}
}

int main()
{
	solve();
	return(0);
}