#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUGLOCAL
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;i--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);i--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};

int a[10];
int b[5];
int c[5];

int stoi(string str){
	int res=0;
	rep(i,sz(str)){
		res*=2;
		if(str[i]=='1')++res;
	}
	return res;
}

int fcc(int kk){
	return (kk&1)|(kk&2)<<4|(kk&4)<<8|(kk&8)<<12|(kk&16)<<16;
}

int rev(int kk){
	return ((kk&1)<<4)|((kk&2)<<2)|(kk&4)|((kk&8)>>2)|((kk&16)>>4);
}

set<int> fc(){
	set<int> res;
	int per[]={0,1,2,3,4};
	int ccc[10];
	int revccc[10];
	rep(i,5){
		ccc[c[i]]=fcc(a[c[i]]);
		revccc[c[i]]=fcc(rev(a[c[i]]));
	}
	do{
		rep(bit,1<<5){
			int k=0;
			rep(i,5){
				k<<=1;
				if(bit&1<<i){
					k+=ccc[c[per[i]]];
				}else{
					k+=revccc[c[per[i]]];
				}
			}
			res.insert(k);
		}
	}while(next_permutation(per,per+5));
	return res;
}

set<int> fb(){
	set<int> res;
	int per[]={0,1,2,3,4};
	int revb[10];
	rep(i,5){
		revb[b[i]]=rev(a[b[i]]);
	}
	do{
		if(per[0]>per[4])continue;
		rep(bit,1<<5){
			int k=0;
			rep(i,5){
				k<<=5;
				if(bit&1<<i){
					k+=a[b[per[i]]];
				}else{
					k+=revb[b[per[i]]];
				}
			}
			res.insert(k);
		}
	}while(next_permutation(per,per+5));
	return res;
}

string bitpattern(int ii){
	string res;
	rep(i,5){
		rep(j,5){
			res+=ii&1<<(i*5+j)?"1":"0";
		}
		res+=" ";
	}
	return res;
}

int solve(){
	int i=0;
	rep(j,10){
		int k;
		rep0(k,5){
			if(b[k]==j)break;
		}
		if(k==5)c[i++]=j;
	}
	set<int> bb=fb();
	set<int> cc=fc();
	set<int>::iterator itr=cc.begin();
	int res=0;
	while(itr!=cc.end()){
		if(bb.find(*itr^((1<<25)-1))!=bb.end()){
			++res;
debug<<bitpattern(*itr^((1<<25)-1))<<endl;
		}
		++itr;
	}
	return res/2;
}

int main() {
	string str;
	IL{
		cin>>str;
		if(str=="END")break;
		a[0]=stoi(str);
		repn(i,1,9){
			cin>>str;
			a[i]=stoi(str);
		}
		b[0]=0;
		int res=0;
		repn(i,1,9){
			repn(j,i+1,9){
				repn(k,j+1,9){
					repn(l,k+1,9){
						b[1]=i;
						b[2]=j;
						b[3]=k;
						b[4]=l;
						res+=solve();
					}
				}
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1056