#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
typedef unsigned long long ull;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
vector<vector<int> > AB,A,B;
int Aidx[5],Bidx[5];

unordered_set<ull> S;
ull VtoH(const vector<vector<int> > &v){
  const ull B = 1777771;
  ull res = 0;
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++) res = res * B + (v[i][j]+'0');
  return res;
}

vector<int> rev(vector<int> a){reverse(a.begin(),a.end());return a;}
void mirror(vector<vector<int> > &res){for(int i=0;i<5;i++) res[i] = rev(res[i]);}

vector<vector<int> > rot(const vector<vector<int> > &a){
  vector<vector<int> > res(5,vector<int>(5));
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++) res[i][j] = a[4-j][i];
  return res;
}

void insert(vector<vector<int> > v){
  S.insert(VtoH(v));
  v = rot(v) , v = rot(v), S.insert(VtoH(v));
  mirror(v), S.insert(VtoH(v));
  v = rot(v) , v = rot(v), S.insert(VtoH(v));
}

bool canPut(int idx,int j){
  int a = 1, b = 1;
  for(int i=0;i<5;i++) if(A[i][j] == B[idx][i]) a = 0;
  for(int i=0;i<5;i++) if(A[i][j] == B[idx][4-i]) b = 0;
  return a || b;
}

bool can(){
  int used = 0;
  for(int i=0;i<5;i++){
    for(int nx=0;nx<5;nx++){
      if((used>>nx&1) || !canPut(nx,i)) continue;
      Bidx[i] = nx;
      used |= (1<<nx);
      break;
    }
  }
  return used == (1<<5)-1;
}

int solve(){
  S.clear();
  int res = 0;
  for(int i=0;i<5;i++) Aidx[i] = i;
  for(int bit=0;bit<(1<<10);bit++){
    if(__builtin_popcount(bit) != 5) continue;    
    A.clear();B.clear();
    for(int i=0;i<10;i++) (bit>>i&1)? A.push_back(AB[i]):B.push_back(AB[i]);
    vector<vector<int> > tmp = A;
    do{
      for(int a=0;a<(1<<5);a++){
        for(int i=0;i<5;i++) A[Aidx[i]] = (a>>i&1)? rev(tmp[i]):tmp[i];
        if(!can() || S.count(VtoH(A))) continue;
        insert(A);
        res++;
      }
    } while(next_permutation(Aidx,Aidx+5));
  }
  return res/2;
}

signed main(){
  while(1){
    AB.clear();
    for(int i=0;i<10;i++){
      string str;
      cin>>str;
      if(str == "END") return 0;
      vector<int> tmp(5);
      for(int j=0;j<5;j++) tmp[j] = str[j] - '0';
      AB.push_back(tmp);
    }
    cout<<solve()<<endl;
  }
  return 0;
}