#include <iostream>
using namespace std;

#define REP(i,n,m) for(int i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)
#define rev(s) (string((s).rbegin(),(s).rend()))

int ans;
string s[10],rs[10];
char p[10][10];
bool flg[10];

void solve(int rem){
	if(rem == 10){
		ans++;
		return;
	}

	int pos = rem / 2;

	if(rem % 2 == 0){
		int len = rem / 2;
		string tmp = "";
		rep(i,len) tmp += p[pos][i];
		rep(i,10){
			if(!flg[i]){
				flg[i] = true;

				if(s[i].substr(0,len) == tmp){
					rep(j,5) p[pos][j] = s[i][j];
					solve(rem+1);
				}
				if(s[i]!=rs[i] && rs[i].substr(0,len) == tmp){
					rep(j,5) p[pos][j] = rs[i][j];
					solve(rem+1);
				}

				flg[i] = false;
			}
		}
	}
	else{
		int len = rem / 2 + 1;
		string tmp = "";
		rep(i,len) tmp += p[i][pos]=='0' ? '1' : '0';
		rep(i,10){
			if(!flg[i]){
				flg[i] = true;

				if(s[i].substr(0,len) == tmp){
					rep(j,5) p[j][pos] = s[i][j]=='0' ? '1' : '0';
					solve(rem+1);
				}
				if(s[i]!=rs[i] && rs[i].substr(0,len) == tmp){
					rep(j,5) p[j][pos] = rs[i][j]=='0' ? '1' : '0';
					solve(rem+1);
				}

				flg[i] = false;
			}
		}
	}
}

int main(void){
	while(1){
		rep(i,10){
			if(cin>>s[i] && s[i]=="END") return 0;
			rs[i] = rev(s[i]);
		}
		fill(flg,flg+10,false);
		ans = 0;
		solve(0);
		cout<<ans/8<<endl;
	}

	return 0;
}