#include<iostream>
#include<set>
using namespace std;

char m[5][5];
char inp[10][5];
int cnt = 0;// answer is cnt/8

bool equal(int form,int forinp,bool flag){
  if(  flag == false){
    for(int i=0;i<5;i++)
      if ( m[form][i] == inp[forinp][i] )return false;
  }else {
    for(int i=0;i<5;i++)
      if ( m[form][i] == inp[forinp][5-i-1] )return false;
  }
  return true;
}

bool check(bool *used){
  bool cpused[10];
  int val[5];
  for(int i=0;i<10;i++)cpused[i]=used[i];
  for(int i=0;i<5;i++){
    bool flag = false;
    for(int j=0;j<10;j++){
      if(  cpused[j] == true)continue;
      if (equal(i,j,false)||equal(i,j,true) ){
	cpused[j]=true;
	flag = true;
	val[i] = j;
	break;	
      }
    }
    if ( flag == false)return false;
  }


  return true;
}


void solve(bool *used,int now){
  if ( now == 5){
    if ( check(used))cnt++;
    return;
  }
  
  for(int i=0;i<10;i++){
    if ( used[i] == true)continue;
    used[i]=true;
    for(int j=0;j<5;j++)m[j][now]=inp[i][j];
    solve(used,now+1);
    
    if ( inp[i][0] == inp[i][4] &&
	  inp[i][1] == inp[i][3]){used[i]=false;continue;}

    for(int j=0;j<5;j++)m[j][now]=inp[i][5-j-1];
    solve(used,now+1);
    used[i]=false;
  }
  return;
}


int main(){
  while(cin>>inp[0] && inp[0][0] != 'E'){
    for(int i=1;i<10;i++)cin>>inp[i];
    cnt = 0;
    bool used[10]={0};
    solve(used,0);
    //cout << cnt << " " << cnt %8 << endl;
    cout << cnt/8 << endl;
  }
  return false;
}