#include <cstdio>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <map>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int N = 410;

struct Col{ 
	int c1, c2, c3, c4;
	bool operator < (const Col& S) const {
		if (c1 != S.c1) return c1 < S.c1;
		if (c2 != S.c2) return c2 < S.c2;
		if (c3 != S.c3) return c3 < S.c3;
		return c4 < S.c4;
	}
	bool operator == (const Col& S) {
		return c1 == S.c1 && c2 == S.c2 && c3 == S.c3 && c4 == S.c4;	
	}
	
} c[N];
map<Col, int> m;

void add(Col x, int v)
{
	Rep(i, 4){
		m[x] += v;
		int tmp = x.c1;
		x.c1 = x.c2, x.c2 = x.c3, x.c3 = x.c4, x.c4 = tmp;
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	Rep(i, n) {
		scanf("%d%d%d%d", &c[i].c1, &c[i].c2, &c[i].c3, &c[i].c4);
		m[(Col){c[i].c1, c[i].c2, c[i].c3, c[i].c4}] ++;
		m[(Col){c[i].c2, c[i].c3, c[i].c4, c[i].c1}] ++;
		m[(Col){c[i].c3, c[i].c4, c[i].c1, c[i].c2}] ++;
		m[(Col){c[i].c4, c[i].c1, c[i].c2, c[i].c3}] ++;
	}
	LL ans = 0;
	Rep(i, n) for (int j = i + 1; j <= n; j ++) {
		int ti = m[c[i]], tj = m[c[j]];
		if (ti) add(c[i], -1); if (tj) add(c[j], -1);
		Col tmp = (Col){c[j].c4, c[j].c3, c[j].c2, c[j].c1};
		Rep(k, 4) {
			LL tans = 1;
			int mt1, mt2, mt3, mt4;
			Col t1 = (Col){tmp.c1, tmp.c2, c[i].c2, c[i].c1};
			mt1 = m[t1], tans *= mt1;
			if (mt1) add(t1, -1);
			Col t2 = (Col){tmp.c2, tmp.c3, c[i].c3, c[i].c2};
			mt2 = m[t2], tans *= mt2;
			if (mt2) add(t2, -1);
			Col t3 = (Col){tmp.c3, tmp.c4, c[i].c4, c[i].c3};
			mt3 = m[t3], tans *= mt3;
			if (mt3) add(t3, -1);
			Col t4 = (Col){tmp.c4, tmp.c1, c[i].c1, c[i].c4};
			tans *= m[t4];
			if (mt1) add(t1, 1);
			if (mt2) add(t2, 1);
			if (mt3) add(t3, 1);
			
			int ttmp = tmp.c1;
			tmp.c1 = tmp.c2, tmp.c2 = tmp.c3, tmp.c3 = tmp.c4, tmp.c4 = ttmp;
			ans += tans;
		//	printf("%d %d %d %d %d\n", i, j, k, tans);
		}
		if (ti) add(c[i], 1); if (tj) add(c[j], 1);
	}
	
	printf("%lld\n", ans / 3);
	
	return 0;
}
