#include <bits/stdc++.h>
using namespace std;
int a[10], b[5][5];
char s[10][6];
int fj(int p) {
  int i, j;
  int sm = 0;
  if (p == 5) {
    sm = 1;
  } else {
    for (i = 0; i < 10; ++i) {
      if (a[i]) {
        a[i] = 0;
        for (j = 0; j < 5; ++j) {
          if (b[j][p] == s[i][j] - '0') break;
        }
        if (j == 5) sm += fj(p + 1);
        for (j = 0; j < 5; ++j) {
          if (b[j][p] == s[i][4 - j] - '0') break;
        }
        if (j == 5) sm += fj(p + 1);
        a[i] = -1;
      }
    }
  }
  return sm;
}
int fi(int p) {
  int i, j;
  int sm = 0;
  if (p == 5) {
    sm = fj(0);
  } else {
    for (i = 0; i < 10; ++i) {
      if (a[i]) {
        a[i] = 0;
        for (j = 0; j < 5; ++j) b[p][j] = s[i][j] - '0';
        sm += fi(p + 1);
        for (j = 0; j < 5; ++j) b[p][j] = s[i][4 - j] - '0';
        sm += fi(p + 1);
        a[i] = -1;
      }
    }
  }
  return sm;
}
int main() {
  int i;
  fill(a, a + 10, -1);
  for (;;) {
    for (i = 0; i < 10; ++i) cin >> s[i];
    if (s[0][0] == 'E') break;
    cout << fi(0) / 64 << endl;
  }
  return 0;
}
