#include <bits/stdc++.h>
using namespace std;
int cocoon[10][5];
int area[5][5];
int check(vector<int> a, vector<int> b) {
  int ret = 0;
  if (!a.empty()) {
    int count = a.size();
    for (int i = 0; i < count; i++) {
      vector<int> aa(a);
      int num = a[i];
      aa.erase(aa.begin() + i);
      for (int j = 0; j < 5; j++) {
        area[5 - count][j] = cocoon[num][j];
      }
      ret += check(aa, b);
      for (int j = 0; j < 5; j++) {
        area[5 - count][j] = cocoon[num][4 - j];
      }
      ret += check(aa, b);
    }
  } else if (!b.empty()) {
    int count = b.size();
    for (int i = 0; i < count; i++) {
      vector<int> bb(b);
      int num = b[i];
      bool flag1 = true, flag2 = true;
      for (int j = 0; j < 5; j++) {
        if (area[j][5 - count] == cocoon[num][j]) flag1 = false;
        if (area[j][5 - count] == cocoon[num][4 - j]) flag2 = false;
      }
      if (!flag1 && !flag2) continue;
      bb.erase(bb.begin() + i);
      int buff = 0;
      if (flag1) buff++;
      if (flag2) buff++;
      ret += buff * check(a, bb);
    }
  } else
    return 1;
  return ret;
}
int main(void) {
  char in[50];
  char end[] = "END";
  while (cin >> in) {
    if (in[0] == 'E') break;
    int ans = 0;
    for (int j = 0; j < 5; j++) {
      cocoon[0][j] = in[j] - '0';
    }
    for (int i = 1; i <= 9; i++) {
      cin >> in;
      for (int j = 0; j < 5; j++) {
        cocoon[i][j] = in[j] - '0';
      }
    }
    for (int i = 0; i < 512; i++) {
      vector<int> bita, bitb;
      int bits = 0;
      int num = i;
      for (int j = 0; j <= 9; j++) {
        if (num % 2 != 0)
          bita.push_back(j);
        else
          bitb.push_back(j);
        num = num / 2;
      }
      if (bita.size() != 5) continue;
      bool flag = false;
      ans += check(bita, bitb);
    }
    cout << ans / 32 << endl;
  }
  return 0;
}
