#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

string s[10], t[10];
bool same[10];
bool used[10];
int a[5];

vector<string> x;

set<vector<string>> ans;

void check(){
	int ret = 0;
	rep(i, 1 << 5){
		rep(j, 5){
			if (i&(1 << j)){
				rep(k, 5) x[k][j] = '1' - s[a[j]][k] + '0';
			}
			else{
				rep(k, 5) x[k][j] = '1' - t[a[j]][k] + '0';
			}
		}
		int cnt[10] = {};
		rep(j, 5) rep(k, 10){
			if (used[k]) continue;
			if (x[j] == s[k] || x[j] == t[k]){
				cnt[k] = 1;
				break;
			}
		}
		if (accumulate(cnt, cnt + 10, 0) == 5){
			ans.insert(x);
		}
	}
}

void dfs(int n){
	if (n == 5){
		check();
		return;
	}
	rep(i, 10){
		if (used[i]) continue;
		used[i] = true;
		a[n] = i;
		dfs(n + 1);
		used[i] = false;
	}
	return;
}

int main(){
	x.resize(5);
	rep(i, 5) x[i].resize(5);
	while (1){
		ans.clear();
		cin >> s[0];
		if (s[0] == "END") break;
		FOR(i, 1, 10) cin >> s[i];
		rep(i, 10) t[i] = string(rbegin(s[i]), rend(s[i]));
		rep(i, 10) if (s[i] == t[i]) same[i] = 1;

		dfs(0);
		cout << ans.size()/8 << endl;
	}

	return 0;
}