#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

int getnum(vector<int>&used, const vector<vector<int>>&walls, vector<vector<int>>&decided,int now) {
	int sum = 0;
	if (now == 10)return 1;
	else 	if (now < 5) {
		const int y = now;
		for (int i = 0; i < 10; ++i) {
			if (used[i])continue;
			else {
				used[i] = true;
				for (int rev = 0; rev < 2; ++rev) {
					if (rev&&walls[i][0] == walls[i][4] && walls[i][1] == walls[i][3])continue;
					for (int x = 0; x < 5; ++x) {
						decided[y][rev?4-x:x] = walls[i][x];
					}
					sum += getnum(used, walls, decided, now + 1);
					for (int x = 0; x < 5; ++x) {
						decided[y][rev ? 4 - x : x] = -1;
					}
				}
				used[i] = false;
				
			}
		}
		
	}
	else {
		const int x = now-5;
		for (int i = 0; i < 10; ++i) {
			if (used[i])continue;
			else {
				used[i] = true;
				for (int rev = 0; rev < 2; ++rev) {
					if (rev&&walls[i][0] == walls[i][4] && walls[i][1] == walls[i][3])continue;

					bool ok = true;
					for (int y = 0; y < 5; ++y) {
						if (decided[rev ? 4 - y : y][x] == walls[i][y])ok = false;
					}
					if (!ok)continue;
					
					sum += getnum(used, walls, decided, now + 1);

				}
				used[i] = false;

			}
		}

	}
	return sum;
}

int main() {
	while (1) {
		vector<vector<int>>walls (10);
		for (int i = 0; i < 10; ++i) {
			string st; cin >> st;
			if (st == "END")return 0;
			else {
				for (int j = 0; j< 5; ++j) {
					walls[i].push_back(st[j] == '1');
				}
			}
		}
		vector<int>used(10, false);
		vector<vector<int>>decided(5, vector<int>(5, -1));
		int ans = getnum(used, walls, decided, 0);
		cout << ans/8<< endl;
	}
	return 0;
}