#include<bits/stdc++.h>
using namespace std;
vector <int> vec[2100],ths[4];
map<vector <int>,int>mp;
void leg(vector <int> &vec)
{if (vec.size()!=4) assert(0);
	vector <int> ls=vec;
	for (int i=1;i<=4;i++)
	{
		int t=vec[0];vec[0]=vec[1];vec[1]=vec[2];vec[2]=vec[3];vec[3]=t;
		if (ls>vec) ls=vec;
	}
	vec=ls;
}
int gnum(vector <int> &vec)
{
	int ans=0;
	for (int i=1;i<=4;i++)
	{
		if ((vec[0]==vec[(0+i)%4])&&(vec[1]==vec[(1+i)%4])&&(vec[2]==vec[(2+i)%4])&&(vec[3]==vec[(3+i)%4]))
			ans++;
	}
	return ans;
}
int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		vec[i].resize(4);
		scanf("%d%d%d%d",&vec[i][0],&vec[i][1],&vec[i][2],&vec[i][3]);
		leg(vec[i]);mp[vec[i]]++;
	}
	for (int i=0;i<4;i++) ths[i].resize(4);
	long long ans=0;
	for (int i=1;i<=n;i++)
	for (int j=1;j<i;j++)
	{
		mp[vec[i]]--;mp[vec[j]]--;
		vector <int> x=vec[i],y=vec[j];reverse(x.begin(),x.end());
		for (int d=0;d<4;d++)
		{
			ths[0][0]=x[0];ths[0][1]=x[1];ths[0][2]=y[1];ths[0][3]=y[0];
			ths[1][0]=x[1];ths[1][1]=x[2];ths[1][2]=y[2];ths[1][3]=y[1];
			ths[2][0]=x[2];ths[2][1]=x[3];ths[2][2]=y[3];ths[2][3]=y[2];
			ths[3][0]=x[3];ths[3][1]=x[0];ths[3][2]=y[0];ths[3][3]=y[3];
			long long p=1;
			for (int t=0;t<4;t++)
			{
				leg(ths[t]);
				p*=gnum(ths[t])*mp[ths[t]];
				mp[ths[t]]--;
			}
			ans+=p;
			for (int t=0;t<4;t++) mp[ths[t]]++;
			int ls=y[0];y[0]=y[1];y[1]=y[2];y[2]=y[3];y[3]=ls;
		}
		mp[vec[i]]++;mp[vec[j]]++;
	}
	cout<<ans/3<<endl;
}