#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<deque>
#include<cmath>
using namespace std;


int main() {

    int n;
    while(cin >> n && n) {
        vector<vector<int> > cases(n + 1, vector<int>(9)); 

        char s, t, b;
        cin >> s >> t >> b;
        int start, battery, junk;
        start = (int)s - 'A';
        battery = (int)t - 'A';
        junk = (int)b - 'A';

        for(int i = 0; i <= 8; i++) {
            cases[0][i] = 0;
        }
        cases[0][battery] = 1;

        for(int i = 1; i <= n; i++) {
            for (int j = 0; j <= 8; j++) {
                cases[i][j] = 0;
                // up
                if (j >= 3 && j - 3 != junk) {
                    cases[i][j] += cases[i-1][j-3];
                } else {
                    cases[i][j] += cases[i-1][j];
                }

                // down
                if (j <= 5 && j + 3 != junk) {
                    cases[i][j] += cases[i-1][j+3];
                } else {
                    cases[i][j] += cases[i-1][j];
                }

                // right
                if (j % 3 != 2 && j + 1 != junk) {
                    cases[i][j] += cases[i-1][j+1];
                } else {
                    cases[i][j] += cases[i-1][j];
                }

                // left
                if (j % 3 != 0 && j - 1 != junk) {
                    cases[i][j] += cases[i-1][j-1];
                } else {
                    cases[i][j] += cases[i-1][j];
                }
            }

        }

        printf("%.8f", (double)cases[n][start] / pow(4.0, n));
        cout << endl;
    }
     
    return 0;
}