#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;
double dp[16][9];

void room(char c,int &x){
	switch(c){
		case 'A':
		x=0;
		break;
		
		case 'B':
		x=1;
		break;
		
		case 'C':
		x=2;
		break;
			
		case 'D':
		x=3;
		break;
		
		case 'E':
		x=4;
		break;
		
		case 'F':
		x=5;
		break;
		
		case 'G':
		x=6;
		break;
		
		case 'H':
		x=7;
		break;
		
		case 'I':
		x=8;
		break;
		
		default:
		break;
	}
}

int main(){
	int n;
	while(cin>>n&&n){
		char s,t,b;
		cin >> s >> t >> b;
		int sr,tr,br;
		room(s,sr);
		room(t,tr);
		room(b,br);
		for(int i=0; i<=n; ++i){
			for(int j=0; j<9; ++j){
				dp[i][j]=0;
			}
		}
		dp[0][sr]=1;
		for(int i=1; i<=n; ++i){
			for(int j=0; j<9; ++j){
				/*
				if(j!=br){
					switch(j){
						case 0:
						dp[i][j]+=(dp[i-1][1]/2+dp[i-1][3]/2+dp[i-1][0])/2;
						break;
						
						case 1:
						dp[i][j]+=(dp[i-1][0]+dp[i-1][4]+dp[i-1][2]+dp[i-1][1])/4;
						break;
						
						case 2:
						dp[i][j]+=(dp[i-1][1]/2+dp[i-1][5]/2+dp[i-1][2])/2;
						break;
						
						case 3:
						dp[i][j]+=(dp[i-1][0]+dp[i-1][4]+dp[i-1][6]+dp[i-1][3])/4;
						break;
					
						case 4:
						dp[i][j]+=(dp[i-1][1]+dp[i-1][5]+dp[i-1][7]+dp[i-1][3])/4;
						break;
					
						case 5:
						dp[i][j]+=(dp[i-1][2]+dp[i-1][4]+dp[i-1][8]+dp[i-1][5])/4;
						break;
						
						case 6:
						dp[i][j]+=(dp[i-1][3]/2+dp[i-1][7]/2+dp[i-1][6])/2;
						break;
						
						case 7:
						dp[i][j]+=(dp[i-1][6]+dp[i-1][4]/2+dp[i-1][8]/2+dp[i-1][7]/2)/2;
						break;
						
						case 8:
						dp[i][j]+=(dp[i-1][5]/2+dp[i-1][7]/2+dp[i-1][8])/2;
						break;
						
						default:
						break;
					}
				}
				*/
				if(j%3!=0&&j-1!=br){
					dp[i][j]+=dp[i-1][j-1]/4;
				} else {
						dp[i][j]+=dp[i-1][j]/4;
				}
				if(j>=3&&j-3!=br){
					dp[i][j]+=dp[i-1][j-3]/4;
				} else{
					dp[i][j]+=dp[i-1][j]/4;
				}
				if(j%3!=2&&j+1!=br){
					dp[i][j]+=dp[i-1][j+1]/4;
				} else {
					dp[i][j]+=dp[i-1][j]/4;
				}
				if(j<=5&&j+3!=br){
					dp[i][j]+=dp[i-1][j+3]/4;
				} else {
					dp[i][j]+=dp[i-1][j]/4;
				}
			}
		}
		printf("%.8f\n",dp[n][tr]);
		//cout << dp[n][tr] << "\n";
	}
	return 0;
}