#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
long long read()
{
	char ch=getchar();long long x=0,ff=1;
	while(ch<'0'||ch>'9') {if(ch=='-') ff=-ff;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*ff;
}
void write(long long aa)
{
	if(aa<0) putchar('-'),aa=-aa;
	if(aa>9) write(aa/10);
	putchar(aa%10+'0');
	return;
}
long long n;
long long bin[5],ans;
long long a[405][4],A[4],B[4];
unordered_map<long long,long long>mp;
long long gao(long long aa,long long bb)
{
	long long qwq=0;
	for(long long j=0;j<4;++j) qwq+=bin[j]*a[aa][(bb+j)%4];
	return qwq;
}
long long md(long long aa,long long bb,long long cc)
{
	a[n+1][0]=A[aa];a[n+1][1]=B[aa];
	a[n+1][2]=B[bb];a[n+1][3]=A[bb];
	long long tmp=gao(n+1,0);
	if(!mp.count(tmp)) return 0;tmp=mp[tmp];
	for(long long i=0;i<4;++i) mp[gao(n+1,i)]-=cc;
	return tmp;
}
void getans()
{
	ans+=1ll*md(0,1,1)*md(1,2,1)*md(2,3,1)*md(3,0,1);
	md(0,1,-1);md(1,2,-1);md(2,3,-1);md(3,0,-1);
	return;
}
int main()
{
	n=read();bin[0]=1;
	for(long long i=1;i<4;++i) bin[i]=bin[i-1]*1000;
	for(long long i=1;i<=n;++i) 
	{
		for(long long j=0;j<4;++j) a[i][j]=read();
		for(long long j=0;j<4;++j) mp[gao(i,j)]++;
	}
	for(long long i=1;i<=n;++i)
	{
		for(long long j=0;j<4;++j) mp[gao(i,j)]--,A[j]=a[i][j];
		for(long long j=i+1;j<=n;++j)
		{
			for(long long l=0;l<4;++l) mp[gao(j,l)]--;
			swap(a[j][0],a[j][1]);swap(a[j][2],a[j][3]);
			for(long long l=0;l<4;++l)
			{
				for(long long k=0;k<4;++k) B[k]=a[j][(k+l)%4];
				getans();
			}
			swap(a[j][0],a[j][1]);swap(a[j][2],a[j][3]);
			for(long long l=0;l<4;++l) mp[gao(j,l)]++;
		}
		for(long long j=0;j<4;++j) mp[gao(i,j)]++;
	}
	write(ans/3);
	return 0;
}