#include <bits/stdc++.h>
using namespace std;
int mp[3][3];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int ans, all;
int n;
char s, t, b;
void saiki(int x, int y, int bat) {
  if (n == bat) {
    all++;
    if ((t - 'A') % 3 == x && (t - 'A') / 3 == y) ans++;
    return;
  }
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (nx < 0 || ny < 0 || nx >= 3 || ny >= 3)
      saiki(x, y, bat + 1);
    else if ((b - 'A') % 3 == nx && (b - 'A') / 3 == ny)
      saiki(x, y, bat + 1);
    else
      saiki(nx, ny, bat + 1);
  }
}
int main() {
  while (1) {
    cin >> n;
    if (n == 0) break;
    ans = all = 0;
    cin >> s >> t >> b;
    saiki((s - 'A') % 3, (s - 'A') / 3, 0);
    cout << ans << " " << all << endl;
    printf("%.8f\n", 1.0 * ans / all);
  }
  return 0;
}
