#include<iostream>
#include<sstream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cassert>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)

using namespace std;
string cocoon[10];
string G[5];
set<string> usecase;
int ans;
int perm[5];

bool check(int p,int used)
{
  if(p >= 5)return true;

  rep(i,10)
    {
      if((used >> i) & 1)continue;

      bool ok = true;
      rep(j,5)
	{
	  //if(cocoon[j][perm[p]] == cocoon[i][j])
	  if(G[j][p] == cocoon[i][j])
	    {
	      ok = false;
	      break;
	    }
	}
      if(ok)
	if(check(p+1,used|(1<<i)))return true;
	
      ok = true;
      rep(j,5)
	{
	  //if(cocoon[j][perm[p]] == cocoon[i][4-j])
	  if(G[j][p] == cocoon[i][4-j])
	    {
	      ok = false;
	      break;
	    }
	}
      if(ok)
	if(check(p+1,used|(1<<i)))return true;
	
    }
  return false;
}

void dfs(int p,int used)
{
  if(p >= 5)
    {
      if(check(0,used))
	{
	  string use="";
	  rep(i,5)use += cocoon[perm[i]];
	  usecase.insert(use);
	}
      return;
    }

  rep(i,10)
    {
      if((used >> i) & 1)continue;
      perm[p] = i;
      G[p] = cocoon[i];
      dfs(p+1,used|(1<<i));

      reverse(cocoon[i].begin(),cocoon[i].end());
      G[p] = cocoon[i];
      dfs(p+1,used|(1<<i));
      reverse(cocoon[i].begin(),cocoon[i].end());
    }
}

int main()
{
  while(cin >> cocoon[0],cocoon[0][0] != 'E')
    {
      REP(i,1,10)cin >> cocoon[i];
      usecase.clear();

      dfs(0,0);
      cout << usecase.size()/8 << endl;
    }
  return 0;
}



/*
#include<iostream>
#include<sstream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cassert>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)

using namespace std;



string cocoon[10];
int perm[5];
char G[5][5];
set<string> usecase;
int ans;


void print()
{
  cout << "print----" << endl;

  rep(y,5)
    {
      rep(x,5)
	{
	  cout << G[y][x];
	  //assert(G[y][x] == '0' || G[y][x] == '1');
	}
      cout << endl;
    }
  cout << endl;
}

void rotate90(int x,int y,int a)
{
  int tmp[a+1][a+1];
  int X = x;
  REP(i,y,y+a)
    {
      REP(j,x,x+a)
	{
	  tmp[i-y][j-x] = G[(y+a-1)-(j-x)][X];
	}
      X++;
    }
  
  rep(i,a)
   rep(j,a)
    G[i+y][j+x] = tmp[i][j];
}

inline void revG(){ rep(y,5)rep(x,5)G[y][x] = (G[y][x]=='0'?'1':'0'); }

bool check(int used)
{
  revG();
  bool ok = false;
  rep(_,4)
    {
      if(!ok)
	{
	  string rem[5];
	  rep(x,5)rep(y,5)rem[x] += string(1,G[y][x]);

	  int store = used;
	  int counter = 0;
	  rep(i,5)
	    {
	      if(ok)break;
	      rep(j,10)
		{
		  if((used >> j) & 1)continue;
		  if(cocoon[j] == rem[i])
		    {
		      counter++;
		      used |= (1<<j);
		      break;
		    }
		}
	    }
	  if(counter == 5)
	      ok = true;
	    
	  used = store;
	}
      rotate90(0,0,5);
    }
  revG();
  return ok;
}

string itos(int i)
{
  stringstream ss; ss << i; return ss.str();
}

void dfs(int cnt,int used)
{
  
 if(cnt >= 5)
    {
      string use="";
      rep(y,5)
	{
	  use += itos(perm[y]);
	  //use += cocoon[perm[y]];
	  rep(x,5)G[y][x] = cocoon[perm[y]][x];
	}
      
      if(usecase.find(use) != usecase.end())return;
      if(!check(used))return;
	
      //cout << "ok!!" << endl;
      //print();

      rep(k,4)
	{
	  string dbg = use;
	  use = "";
	  rep(y,5)rep(x,5)use += string(1,G[y][x]);
	  //if(k == 0)assert(dbg == use);
	  usecase.insert(use);
	  rotate90(0,0,5);
	}
      ans++;
      return;
    }


  rep(i,10)
    {
      if((used >> i) & 1)continue;
      perm[cnt] = i;
      dfs(cnt+1,used|(1<<i));

      reverse(cocoon[i].begin(),cocoon[i].end());
      dfs(cnt+1,used|(1<<i));
      reverse(cocoon[i].begin(),cocoon[i].end());
    }

}

int main()
{
  while(cin >> cocoon[0],cocoon[0][0] != 'E')
    {
      ans = 0;
      usecase.clear();
      REP(i,1,10)cin >> cocoon[i];
      dfs(0,0);
      cout << ans << endl;
    }
  return 0;
}

*/

/*
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<climits>
#include<iomanip>
#include<sstream>
#include<cassert>
#include<bitset>
#include<ctime>
#include<set>
#include<map>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)

using namespace std;
string cocoon[10];
string frame[5];
int cnt;

bool check(int phase,int type)
{
  bool f = phase%2;
  rep(i,5)
    {
      char c = (cocoon[type][i] == '1'?'0':'1');
      //cout << cocoon[type][i] << " c = " << c << " f = " << f << " frame[i][phase/2] = " << frame[i][phase/2] << endl;  
      if(f  && !((frame[i][phase/2] == c || frame[i][phase/2] == 'x')))return false;
      if(!f && !((frame[phase/2][i] == c || frame[phase/2][i] == 'x')))return false;
    }
  return true;
}
set<string> used;
void dfs(int phase,int p,string s)
{
  //cout << s  << " : " << phase << endl;
  if(phase >= 10)
    {
      //if(used.find(s) != used.end())return;
      //cout << s << endl;
      //used.insert(s);
      cnt++;
      //cout << cnt << endl;
      return;
    }
  rep(i,10)
    {
      if((p >> i) & 1)continue;
      if(phase%2)
	{
	  if(!check(phase,i))goto Skip3;
	  rep(j,5)frame[j][phase/2] = cocoon[i][j];
	  dfs(phase+1,p|(1<<i),s);
	  rep(j,5)frame[j][phase/2] = 'x';

	Skip3:;
	  string pres = cocoon[i];
	  reverse(cocoon[i].begin(),cocoon[i].end());	 
	  if(pres == cocoon[i])goto Skip4;
 	  if(!check(phase,i))goto Skip4;
	  rep(j,5)frame[j][phase/2] = cocoon[i][j];
	  dfs(phase+1,p|(1<<i),s);
	  rep(j,5)frame[j][phase/2] = 'x';

	Skip4:;
	  reverse(cocoon[i].begin(),cocoon[i].end());
	}
      else
	{
	  if(!check(phase,i))goto Skip;
	  frame[phase/2] = cocoon[i];
	  dfs(phase+1,p|(1<<i),s+" "+cocoon[i]);
	  frame[phase/2] = string(5,'x');
	  
	Skip:;
	  string pres = cocoon[i];
	  reverse(cocoon[i].begin(),cocoon[i].end());
	  if(pres == cocoon[i])goto Skip2;
	  if(!check(phase,i))goto Skip2;
	  frame[phase/2] = cocoon[i];
	  dfs(phase+1,p|(1<<i),s+" "+cocoon[i]);
	  frame[phase/2] = string(5,'x');
	  
	Skip2:;
	  reverse(cocoon[i].begin(),cocoon[i].end());
	}
    }
}

int main()
{

  string line;
  while(true)
    {
      cin >> line;
      if(line == "END")break;
      cnt = 0;
      cocoon[0] = line;
      REP(i,1,10)cin >> cocoon[i];
      rep(i,5)frame[i] = string(5,'x');
      string s = "";
      dfs(0,0,s);

      cout << cnt << endl;
    }
  return 0;
}
*/
/*
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<climits>
#include<iomanip>
#include<sstream>
#include<cassert>
#include<bitset>
#include<set>
#include<map>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define _A_ true
using namespace std;
string cocoon[10];
string G[5];
set<string> mem;
int ans;

bool check(int used)
{
  string reg = G[0] + G[1] + G[2] + G[3] + G[4];
  if(mem.count(reg))return 0;//already counted
  mem.insert(reg);
  //cout << reg << endl;

  map<string,bool> rem;
  rep(i,10)
    {
      if((used >> i) & 1)continue;
      string vip = cocoon[i];
      rem[vip] = true;
      //cout << "in :: " << vip << endl;
      reverse(vip.begin(),vip.end());
      //cout << "in :: " << vip << endl;
      rem[vip] = true;
    }

  bool ch = true;
  string rG[5] = G;
 

  rep(i,5)
    rep(j,5)
      rG[i][j] = (G[j][i]=='1'?'0':'1');
 
  rep(i,5)
    {
      string px = rG[i];
      string rpx = px;
      reverse(rpx.begin(),rpx.end());
      if(!(rem[px] || rem[rpx]))
	{
	  return false;
	}
    }
  return true;
}

int dfs(int used,int p)
{
  if(p >= 5)
    {
      return check(used);
    }

  int ret = 0;
  rep(i,10)
    {
      if((used >> i) & 1)continue;
      G[p] = cocoon[i];
      ret += dfs(used|(1<<i),p+1);

      reverse(G[p].begin(),G[p].end());
      ret += dfs(used|(1<<i),p+1);
    }
  return ret;
}

int main()
{
  while(_A_)
    {
      string line;
      getline(cin,line);
      if(line == "END")break;
      mem.clear();
      ans = 0;
      stringstream ss;
      ss << line;
      for(int i=0;!(ss >> line).fail();i++)
	{
	  cocoon[i] = line;
	}
      cout << "-+-+-+-+-+-+-+-" << endl;
      cout << dfs(0,0) << endl;
    }
  return 0;
}

*/

Measured memory_bytes: 1224