// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,a,b) for (int i=(a); i<(b); i++)

#define per(i,a,b) for (int i=(b)-1; i>=(a); i--)

#define debug(x) cout << #x << " => " << x << endl

using namespace std;

typedef long long ll;



#define fi first

#define se second

#define mp make_pair

typedef pair<int,int> pii;



#define pb push_back

typedef vector<int> vi;



const int INF = 1e9 + 7;

const int MOD = 1e9 + 7;

const int MAX_N = 7 + 400;

///----------------------------------------------

//int qpow(int



int col[10];

void rote() {

    int tmp[4]; rep(i,0,4) tmp[i]=col[i];

    rep(beg,1,4) {

        int i; for (i=0; i<3&&tmp[(beg+i)%4]==col[i]; ) i++;

        if(tmp[(beg+i)%4]<col[i]) {

            rep(i,0,4) col[i]=tmp[(beg+i)%4];

        }

    }

}



const int B[4]={1000000000, 1000000, 1000, 1};

ll getval() {

    rote();

    ll val=0;

    rep(i,0,4) val+=1ll*col[i]*B[i];

    return val;

}



bool same() {

    rep(i,1,4) if (col[i]!=col[0]) return false;

    return true;

}

bool same2() {

    return col[0]==col[2]&&col[1]==col[3];

}





map<ll,int> num;

int tab[MAX_N][4];

int main() {



    ///freopen ( "xx.in" , "r" , stdin );



    ///init

    ///read

    int n; cin>>n;

    rep(i,0,n) {

        rep(j,0,4) scanf("%d",&col[j]), tab[i][j]=col[j];

        num[getval()]++;

    }



    ///work

    ll ans=0;

    rep(i,0,n) {

        rep(j,0,4) col[j]=tab[i][j]; num[getval()]--;

        rep(j,i+1,n) {

            rep(k,0,4) col[k]=tab[j][k]; num[getval()]--;

            rep(off,0,4) {

                ll tmp=1;

                ///front

                col[0]=tab[i][1]; col[1]=tab[j][(off+0)%4];

                col[3]=tab[i][2]; col[2]=tab[j][(off+3)%4]; rote();

                ll val1 = getval();

                ll tmp1 = same() ? 4 : same2() ? 2 : 1;

                tmp=1ll*tmp*(num[val1]--)*tmp1;

                ///top

                col[0]=tab[i][0]; col[1]=tab[j][(off+1)%4];

                col[3]=tab[i][1]; col[2]=tab[j][(off+0)%4]; rote();

                ll val2 = getval();

                ll tmp2 = same() ? 4 : same2() ? 2 : 1;

                tmp=1ll*tmp*(num[val2]--)*tmp2;

                ///buttom

                col[0]=tab[i][2]; col[1]=tab[j][(off+3)%4];

                col[3]=tab[i][3]; col[2]=tab[j][(off+2)%4]; rote();

                ll val3 = getval();

                ll tmp3 = same() ? 4 : same2() ? 2 : 1;

                tmp=1ll*tmp*(num[val3]--)*tmp3;

                ///back

                col[0]=tab[i][3]; col[1]=tab[j][(off+2)%4];

                col[3]=tab[i][0]; col[2]=tab[j][(off+1)%4]; rote();

                ll val4 = getval();

                ll tmp4 = same() ? 4 : same2() ? 2 : 1;

                tmp=1ll*tmp*(num[val4]--)*tmp4;

                ans=ans+tmp;

                num[val1]++;

                num[val2]++;

                num[val3]++;

                num[val4]++;



            }

            rep(k,0,4) col[k]=tab[j][k]; rote(); num[getval()]++;

       }

    }



    ///print

    cout << ans << endl;









}
























// Optimized solution to the same problem (faster):
#include<cstdio>

#include<map>

#include<algorithm>

using namespace std;

#define LL long long

#define MAXN 400

LL F(LL a,LL b,LL c,LL d)

{

	return a<<30|b<<20|c<<10|d;

}

map<LL,int> G;

void A(LL a,int v)

{

	for(int i=0;i<4;i++)

	{

		G[a]+=v;

		a=(a>>10)|((a&1023)<<30);

	}

}

int a[MAXN][8],n;

LL r,ans,u[4];

int main()

{

	scanf("%d",&n);

	for(int i=0;i<n;i++)

	{

		for(int j=0;j<4;j++)

		{

			scanf("%d",&a[i][j]);

			a[i][j+4]=a[i][j];

		}

		A(F(a[i][0],a[i][1],a[i][2],a[i][3]),1);

	}

	for(int i=0;i<n;i++)

	{

		A(F(a[i][0],a[i][1],a[i][2],a[i][3]),-1);

		for(int j=i+1;j<n;j++)

		{

			A(F(a[j][0],a[j][1],a[j][2],a[j][3]),-1);

			for(int k=0;k<4;k++)

			{

				r=1;

				u[0]=F(a[j][k+1],a[j][k+0],a[i][1],a[i][0]);

				u[1]=F(a[j][k+0],a[j][k+3],a[i][2],a[i][1]);

				u[2]=F(a[j][k+3],a[j][k+2],a[i][3],a[i][2]);

				u[3]=F(a[j][k+2],a[j][k+1],a[i][4],a[i][3]);

				if(G[u[0]]&&G[u[1]]&&G[u[2]]&&G[u[3]])

				{

					r*=G[u[0]];

					A(u[0],-1);

					r*=G[u[1]];

					A(u[1],-1);

					r*=G[u[2]];

					A(u[2],-1);

					r*=G[u[3]];

					ans+=r;

					A(u[0],1);

					A(u[1],1);

					A(u[2],1);

				}

			}

			A(F(a[j][0],a[j][1],a[j][2],a[j][3]),1);

		}

	}

	printf("%lld\n",ans);

}

// Fastest known solution for this problem: