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

int n,c[N][4],e[4][4],f[N];
long long h[N],ans;

int query(int c[]){
	long long tmp=((c[0]*1000ll+c[1])*1000+c[2])*1000+c[3];
	int x=lower_bound(h+1,h+4*n+1,tmp)-h;
	return h[x]==tmp?f[x]:0;
}

void modify(int c[],int t){
	f[lower_bound(h+1,h+4*n+1,((c[0]*1000ll+c[1])*1000+c[2])*1000+c[3])-h]+=t;
	f[lower_bound(h+1,h+4*n+1,((c[1]*1000ll+c[2])*1000+c[3])*1000+c[0])-h]+=t;
	f[lower_bound(h+1,h+4*n+1,((c[2]*1000ll+c[3])*1000+c[0])*1000+c[1])-h]+=t;
	f[lower_bound(h+1,h+4*n+1,((c[3]*1000ll+c[0])*1000+c[1])*1000+c[2])-h]+=t;
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
 
int main(){
	n=read();
	for (int i=1;i<=n;i++){
		c[i][0]=c[n+i][1]=c[2*n+i][2]=c[3*n+i][3]=read();
		c[i][1]=c[n+i][2]=c[2*n+i][3]=c[3*n+i][0]=read();
		c[i][2]=c[n+i][3]=c[2*n+i][0]=c[3*n+i][1]=read();
		c[i][3]=c[n+i][0]=c[2*n+i][1]=c[3*n+i][2]=read();
	}
	for (int i=1;i<=4*n;i++)
		h[i]=((c[i][0]*1000ll+c[i][1])*1000+c[i][2])*1000+c[i][3];
	sort(h+1,h+4*n+1);h[4*n+1]=1e12;
	for (int i=1;i<=n;i++)
		modify(c[i],1);
	
	for (int i=1;i<=4*n;i++)
		for (int j=i+1;j<=4*n;j++)
			if (i%n!=j%n){
				modify(c[i],-1);modify(c[j],-1);
				e[0][0]=c[i][1];e[0][1]=c[i][0];e[0][2]=c[j][1];e[0][3]=c[j][0];
				e[1][0]=c[i][2];e[1][1]=c[i][1];e[1][2]=c[j][0];e[1][3]=c[j][3];
				e[2][0]=c[i][3];e[2][1]=c[i][2];e[2][2]=c[j][3];e[2][3]=c[j][2];
				e[3][0]=c[i][0];e[3][1]=c[i][3];e[3][2]=c[j][2];e[3][3]=c[j][1];
				long long tmp=query(e[0]);modify(e[0],-1);
				tmp*=query(e[1]);modify(e[1],-1);
				tmp*=query(e[2]);modify(e[2],-1);
				ans+=tmp*query(e[3]);
				modify(e[0],1);modify(e[1],1);modify(e[2],1);
				modify(c[i],1);modify(c[j],1);
			}
	printf("%lld\n",ans/12);
	return 0;
}