#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
int getnum(vector<int>& used, const vector<vector<int>>& walls,
           vector<vector<int>>& decided, int now) {
  int sum = 0;
  if (now == 10)
    return 1;
  else if (now < 5) {
    const int y = now;
    for (int i = 0; i < 10; ++i) {
      if (used[i])
        continue;
      else {
        used[i] = true;
        for (int rev = 0; rev < 2; ++rev) {
          for (int x = 0; x < 5; ++x) {
            decided[y][rev ? 4 - x : x] = walls[i][x];
          }
          sum += getnum(used, walls, decided, now + 1);
          for (int x = 0; x < 5; ++x) {
            decided[y][rev ? 4 - x : x] = -1;
          }
        }
        used[i] = false;
      }
    }
  } else {
    const int x = now - 5;
    for (int i = 0; i < 10; ++i) {
      if (used[i])
        continue;
      else {
        used[i] = true;
        for (int rev = 0; rev < 2; ++rev) {
          bool ok = true;
          for (int y = 0; y < 5; ++y) {
            if (decided[rev ? 4 - y : y][x] == walls[i][y]) ok = false;
          }
          if (!ok) continue;
          sum += getnum(used, walls, decided, now + 1);
        }
        used[i] = false;
      }
    }
  }
  return sum;
}
int main() {
  while (1) {
    vector<vector<int>> walls(10);
    for (int i = 0; i < 10; ++i) {
      string st;
      cin >> st;
      if (st == "END")
        return 0;
      else {
        for (int j = 0; j < 5; ++j) {
          walls[i].push_back(st[j] == '1');
        }
      }
    }
    vector<int> used(10, false);
    vector<vector<int>> decided(5, vector<int>(5, -1));
    int ans = getnum(used, walls, decided, 0);
    cout << ans / 64 << endl;
  }
  return 0;
}
