#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int ans;
string s[10],r[10];
string t1[5],t2[5];
bool b[11];
bool check(int p){
  r(i,5)if(t1[i][p]==t2[p][i])return 0;
  return 1;
}
void dfs2(int d){
  if(d==5)ans++;
  else{
    r(i,10)if(!b[i]){
      b[i]=1;
      t2[d]=s[i];
      if(check(d))dfs2(d+1);
      t2[d]=r[i];
      if(check(d))dfs2(d+1);
      b[i]=0;
    }
  }
}
void dfs(int d){
  if(d==5)dfs2(0);
  else{
    r(i,10)if(!b[i]){
      b[i]=1;
      t1[d]=s[i];
      dfs(d+1);
      t1[d]=r[i];
      dfs(d+1);
      b[i]=0;
    }
  }
}
int main(){
  while(cin>>s[0],s[0]!="END"){
    memset(b,0,sizeof(b));
    ans=0;
    r[0]=s[0];
    reverse(r[0].begin(),r[0].end());
    r(i,9){
      cin>>s[i+1];
      r[i+1]=s[i+1];
      reverse(r[i+1].begin(),r[i+1].end());
    }
    int p=0;
    r(i,10)if(s[i]==r[i])p++;
    dfs(0);
    cout<<ans/(pow(2,p)*8)<<endl;
  }
}