// Slower C++ solution:
#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;









}
























// Faster C++ solution for the same problem (measured speedup: 1.1272459764824823x):
#include<cstdio>

#include<map>

using namespace std;

const int MAXN=405;



long long encode(long long a,long long b,long long c,long long d)

{

	return (a<<30LL)|(b<<20LL)|(c<<10LL)|d;

}



map<long long,long long> cnt;

void Add(long long c,int delta)

{

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

	{

		cnt[c]+=delta;

		c=(c>>10LL)|((c&1023LL)<<30LL);

	}

}



int n;

int c[MAXN][4];



int main()

{

	scanf("%d",&n);

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

	{

		scanf("%d%d%d%d",c[i],c[i]+1,c[i]+2,c[i]+3);

		Add(encode(c[i][0],c[i][1],c[i][2],c[i][3]),1);

	}

	long long ans=0;

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

	{

		Add(encode(c[i][0],c[i][1],c[i][2],c[i][3]),-1);

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

		{

			Add(encode(c[j][0],c[j][1],c[j][2],c[j][3]),-1);

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

			{

				long long u[4]=

				{encode(c[i][1],c[i][0],c[j][(k+1)&3],c[j][(k+0)&3]),

				 encode(c[i][0],c[i][3],c[j][(k+2)&3],c[j][(k+1)&3]),

				 encode(c[i][3],c[i][2],c[j][(k+3)&3],c[j][(k+2)&3]),

				 encode(c[i][2],c[i][1],c[j][(k+0)&3],c[j][(k+3)&3])

				};

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

				{

					long long tmp=1;

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

						tmp*=cnt[u[l]],Add(u[l],-1);

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

						Add(u[l],1);

					ans+=tmp;

				}

			}

			Add(encode(c[j][0],c[j][1],c[j][2],c[j][3]),1);

		}

	}

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

	

	return 0;

}