#include<iostream>
#include<cstdio>
using namespace std;
char s,t,b;
char fld[3][3]={"ABC","DEF","GHI"};
int ans,sum,dx[]={1,0,-1,0},dy[]={0,1,0,-1};
void rep(int now,int y,int x){
	int X,Y;
	if(now==0){
		sum++;
		if(fld[y][x]==t){
			ans++;
		}
		return ;
	}
	for(int i=0;i<4;i++){
		X=x+dx[i];
		Y=y+dy[i];
		if(X>=0&&X<3&&Y>=0&&Y<3&&fld[Y][X]!=b){
			rep(now-1,Y,X);
		}
		else{
			rep(now-1,y,x);
		}
	}
}
int main(){
	int n;
	while(cin>>n,n){
		cin>>s>>t>>b;
		sum=0;
		ans=0;
		for(int i=0;i<3;i++)
		for(int j=0;j<3;j++){
			if(fld[i][j]==s)
			rep(n,i,j);
		}
		cout<<ans<<' '<<sum<<endl;
		printf("%.8lf\n",(double)ans/sum);
	}
	return 0;
}