#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int cocoon[5][5];
bool used[10], sameRev[10];

int solve(vector<string>& slit, int cnt)
{
	int ans = 0;

	if (cnt < 5) {
		for (unsigned int i = 0; i < slit.size(); ++i) {
			if (used[i])
				continue;

			used[i] = true;
			for (int j = 0; j < 5; ++j)
				cocoon[cnt][j] += (slit[i][j] - '0');
			ans += solve(slit, cnt+1);
			for (int j = 0; j < 5; ++j)
				cocoon[cnt][j] -= (slit[i][j] - '0');

			if (!sameRev[i]) {
				for (int j = 0; j < 5; ++j)
					cocoon[cnt][j] += (slit[i][5-j-1] - '0');
				ans += solve(slit, cnt+1);
				for (int j = 0; j < 5; ++j)
					cocoon[cnt][j] -= (slit[i][5-j-1] - '0');
			}
			used[i] = false;
		}
	} else {
		for (unsigned int i = 0; i < slit.size(); ++i) {
			if (used[i])
				continue;

			used[i] = true;

			bool straight = true;
			for (int j = 0; j < 5; ++j) {
				cocoon[j][cnt-5] += (slit[i][j] - '0');
				if (cocoon[j][cnt-5] != 1)
					straight = false;
			}

			if (straight) {
				if (cnt == 9) {
					bool valid = true;
					for (int y = 0; y < 5 && valid; ++y) {
						for (int x = 0; x < 5 && valid; ++x) {
							if (cocoon[y][x] != 1)
								valid = false;
						}
					}
					if (valid)
						++ans;
				} else {
					ans += solve(slit, cnt+1);
				}
			}
			for (int j = 0; j < 5; ++j)
				cocoon[j][cnt-5] -= (slit[i][j] - '0');


			if (!sameRev[i]) {
				bool rev = true;
				for (int j = 0; j < 5; ++j) {
					cocoon[j][cnt-5] += (slit[i][5-j-1] - '0');
					if (cocoon[j][cnt-5] != 1)
						rev = false;
				}

				if (rev) {
					if (cnt == 9) {
						bool valid = true;
						for (int y = 0; y < 5 && valid; ++y) {
							for (int x = 0; x < 5 && valid; ++x) {
								if (cocoon[y][x] != 1)
									valid = false;
							}
						}
						if (valid)
							++ans;
					} else {
						ans += solve(slit, cnt+1);
					}
				}
				for (int j = 0; j < 5; ++j)
					cocoon[j][cnt-5] -= (slit[i][5-j-1] - '0');
			}
			used[i] = false;
		}
	}
	return ans;
}

int main()
{
	vector<string> slit(10);
	while (cin >> slit[0]) {
		if (slit[0] == "END")
			break;

		for (int i = 1; i < 10; ++i)
			cin >> slit[i];

		for (int i = 0; i < 10; ++i) {
			string s = slit[i];
			reverse(s.begin(), s.end());
			if (slit[i] == s)
				sameRev[i] = true;
			else
				sameRev[i] = false;
		}

		for (int i = 0; i < 5; ++i) {
			for (int j = 0; j < 5; ++j)
				cocoon[i][j] = 0;
		}
		for (int i = 0; i < 10; ++i)
			used[i] = false;
		cout << (solve(slit, 0) >> 3) << endl;
	}
	return 0;
}