#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define N 410
#define ll long long
using namespace std;
int n, a[N][4];
ll ans, ans1, b[5];
map<ll, int>mp;
inline ll id(ll a, int b, int c, int d){return (a<<30)+(b<<20)+(c<<10)+d;}
inline void ins(ll x, int y){
	int a=x>>30, b=(x>>20)&1023, c=(x>>10)&1023, d=x&1023;
	mp[id(a, b, c, d)]+=y;
	mp[id(b, c, d, a)]+=y;
	mp[id(c, d, a, b)]+=y;
	mp[id(d, a, b, c)]+=y;
}
int main(){
	scanf("%d", &n);
	mp.clear();
	for(int i=1; i<=n; i++){
		for(int j=0; j<=3; j++)scanf("%d", &a[i][j]);
		ins(id(a[i][0], a[i][1], a[i][2], a[i][3]), 1);
	}
	ans=0;
	for(int i=1; i<=n-5; i++){
		ins(id(a[i][0], a[i][1], a[i][2], a[i][3]), -1);
		for(int j=i+1; j<=n; j++)
			for(int k=0; k<=3; k++){
				ins(id(a[j][0], a[j][1], a[j][2], a[j][3]), -1);
				b[1]=id(a[i][0], a[j][(0+k)%4], a[j][(3+k)%4], a[i][1]);
				b[2]=id(a[i][1], a[j][(3+k)%4], a[j][(2+k)%4], a[i][2]);
				b[3]=id(a[i][2], a[j][(2+k)%4], a[j][(1+k)%4], a[i][3]);
				b[4]=id(a[i][3], a[j][(1+k)%4], a[j][(0+k)%4], a[i][0]);
				if(mp[b[1]]&&mp[b[2]]&&mp[b[3]]&&mp[b[4]]){
					ans1=1; for(int ii=1; ii<=4; ii++){ans1*=mp[b[ii]]; ins(b[ii], -1);}
					ans+=ans1; for(int ii=1; ii<=4; ii++)ins(b[ii], 1);
				}
				ins(id(a[j][0], a[j][1], a[j][2], a[j][3]), 1);
			}
	}
	printf("%lld", ans);
	return 0;
}