#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

vector<int> F(8, 0);
int getP(vector<int> &o) {
	int k=-1; F[0] = -1;
	for(int i=1; i<8; i++) {
		while(k>=0 && F[k+1] != o[i%4]) k = F[k];
		if(F[k+1] == o[i%4]) k++;
		F[i] = k;
	}
	return 8 / (8 - (k+1)) / 2;
}
void rotate(vector<int> &o) {
	int temp = o.front();
	for(int i=0; i<3; i++) o[i] = o[i+1]; o.back() = temp;
}

const int MAX_N = 4e2 + 10;

int N; 
vector<int> Nr[MAX_N];
map<vector<int>, int> Cnt;

int main() {
	cin >> N;
	for(int i=0; i<N; i++) {
		for(int k=0, x; k<4; k++) scanf("%d", &x), Nr[i].push_back(x);
		for(int k=0; k<4; k++) Cnt[Nr[i]]++, rotate(Nr[i]);
	}
	
	vector<int> cube(8, 0);
	vector<vector<int>> faceIx({vector<int>({5, 4, 1, 0}), vector<int>({4, 7, 2, 1}), vector<int>({7, 6, 3, 2}), vector<int>({6, 5, 0, 3})});
	ll ans = 0;
	for(int l=0; l<N; l++) {
		for(int k=0; k<4; k++) cube[k] = Nr[l][k];
		for(int k=0; k<4; k++) Cnt[Nr[l]]--, rotate(Nr[l]);
		for(int r=l+1; r<N; r++) {
			for(int k=0; k<4; k++) Cnt[Nr[r]]--, rotate(Nr[r]);
			for(int rt=0; rt<4; rt++) {
				for(int k=0; k<4; k++) cube[4+k] = Nr[r][(k+rt)%4];
				ll now = 1;
				vector<vector<int>> faces;
				for(int f=0; f<4; f++) {
					vector<int> face(4, 0);
					for(int k=0; k<4; k++) face[k] = cube[faceIx[f][k]];
					if((now *= Cnt[face]) == 0) break;
					faces.push_back(face);
					for(int k=0; k<4; k++) Cnt[face]--, rotate(face);
				}
				ans += now;
				for(int f=0; f<SZ(faces); f++) for(int k=0; k<4; k++) Cnt[faces[f]]++, rotate(faces[f]);
			}
			for(int k=0; k<4; k++) Cnt[Nr[r]]++, rotate(Nr[r]);
		}
	}
	printf("%lld\n", ans);
	return 0;
}
