#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

double dp[20][10];
int n,s,t,b;

int move(int pos,int x,int y){
	if(pos<3&&y==-1)return pos;
	if(pos>=6&&y==1)return pos;
	if(pos%3==0&&x==-1)return pos;
	if(pos%3==2&&x==1)return pos;
	pos+=x+3*y;
	if(pos==b)return pos-x-3*y;
	return pos;
}

int main() {
	string ss,tt,bb;
	while(n=in()){
		cin>>ss>>tt>>bb;
		s=ss[0]-'A';
		t=tt[0]-'A';
		b=bb[0]-'A';
		memset(dp,0,sizeof(dp));
		dp[0][s]=1;
		int i,j;
		for(i=1;i<=n;i++){
			for(j=0;j<9;j++){
				dp[i][move(j,1,0)]+=dp[i-1][j]/4;
				dp[i][move(j,-1,0)]+=dp[i-1][j]/4;
				dp[i][move(j,0,1)]+=dp[i-1][j]/4;
				dp[i][move(j,0,-1)]+=dp[i-1][j]/4;
			}
		}
		printf("%.12f\n",dp[n][t]);
	}
	return 0;
}