#include <bits/stdc++.h> 
using namespace std;

vector<vector<pair<int, int>>> dn {
	{{ 1, 1 }, { 1, 2 }, { 1, 3 }, { 1, 4 }},
	{{ 1, 4 }, { 2, 4 }, { 3, 4 }, { 4, 4 }},
	{{ 4, 4 }, { 4, 3 }, { 4, 2 }, { 4, 1 }},
	{{ 4, 1 }, { 3, 1 }, { 2, 1 }, { 1, 1 }},
	{{ 1, 1 }, { 2, 2 }, { 3, 3 }, { 4, 4 }},
	{{ 1, 4 }, { 2, 3 }, { 3, 2 }, { 4, 1 }}
};
int n, res = 0;
vector<vector<string>> v, u;

map<string, vector<int>> mp;

void dfs(int idx) {
	for (int i = 1; i <= 4; i++) {
		for (int j = 1; j <= 4; j++) {
			for (int k = 1; k <= 7; k++) {
				if (k <= u[i][j].size())
					cout << u[i][j][k - 1];
				else {
					if (k == 1)
						cout << '.';
					else
						cout << ' '; 
				}
			}
		}
		cout << endl;
	}
	cout << endl;
	if (idx == 6) {
		res++;
		/**/
		return;
	}
	for (int k = 0; k < mp[u[dn[idx][0].first][dn[idx][0].second]].size(); k++) {
		int i = mp[u[dn[idx][0].first][dn[idx][0].second]][k];
		vector<bool> tmp(4);
		bool flag = true;
		for (int j = 0; j < 4; j++) {
			int r = dn[idx][j].first, c = dn[idx][j].second;
			if (u[r][c].empty()) {
				u[r][c] = v[i][j];
				tmp[j] = 1;
			}
			else if (u[r][c] != v[i][j]) {
				flag = false;
				break;
			}
		}
		if (flag)
			dfs(idx + 1);
		for (int j = 0; j < 4; j++) {
			if (tmp[j]) {
				int r = dn[idx][j].first, c = dn[idx][j].second;
				u[r][c] = "";
			}
		}
	}
}

int main() {
	//freopen("idioms.txt", "r", stdin);
	cin >> n;
	v.resize(n + 1, vector<string>(4));
	u.resize(5, vector<string>(5));
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 4; j++) {
			cin >> v[i][j];
		}
		mp[""].push_back(i);
		mp[v[i][0]].push_back(i);
	}
	dfs(0);
	cout << res;
	return 0;
}