#include <bits/stdc++.h>

#define pb push_back

typedef long long ll;

using namespace std;

int n;
vector<int> c[4][401];

int fIdx[4][4] = {
	{1 + 4, 0, 3, 2 + 4},
	{1 + 4, 0 + 4, 1, 0},
	{1, 0 + 4, 3 + 4, 2},
	{3, 2, 3 + 4, 2 + 4}
};
map< vector<int> , int > cnt;


void addFace(vector<int> &v , int val) {
	for (int it = 0 ; it < 4 ; ++it) {
		rotate(v.begin(), v.begin() + 1, v.end());
		cnt[v] += val;
	}
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		for (int j = 0 ; j < 4 ; ++j)c[j][i].resize(4);
		for (int j = 0 ; j < 4 ; ++j) {
			scanf("%d", &c[0][i][j]);
		}
		for (int j = 1 ; j < 4; ++j) {
			c[j][i] = c[j - 1][i];
			rotate(c[j][i].begin(), c[j][i].begin() + 1, c[j][i].end());
		}
		for (int j = 0 ; j < 4 ; ++j)cnt[c[j][i]]++;
	}
	ll res = 0;
	vector<int> myFace;
	myFace.resize(4);
	for (int i = 0 ; i < n ; ++i) {
		for (int rt = 0 ; rt < 4 ; ++rt) {
			cnt[c[rt][i]]--;
		}
		for (int j = i + 1 ; j < n ; ++j) {
			for (int rt2 = 0 ; rt2 < 4 ; rt2++) {
				cnt[c[rt2][j]]--;
			}
			for (int rt2 = 0 ; rt2 < 4 ; rt2++) {
				ll ans =  1;
				vector< vector<int> > allFc;
				for (int faces = 0; faces < 4 ; ++faces) {
					for (int kk = 0 ; kk < 4 ; ++kk) {
						int idx = fIdx[faces][kk];
						myFace[kk]=(idx >= 4 ? c[rt2][j][idx - 4] : c[0][i][idx]);
					}
					ans *= cnt[myFace];
					if (ans == 0)break;
					allFc.push_back(myFace);
					addFace(myFace, -1);
				}
				for (int p = 0; p < allFc.size(); ++p) {
					addFace(allFc[p], +1);
				}
				res += ans;
			}
			for (int rt2 = 0 ; rt2 < 4 ; rt2++) {
				cnt[c[rt2][j]]++;
			}
		}
	}
	cout << res << endl;
	return 0;
}