#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
int n;
struct node{int col[4];
    node nxt(){ return node{col[1],col[2],col[3],col[0]};}
    friend bool operator <(node a,node b)
    {
        for (int i=0;i<4;i++)
            if (a.col[i]!=b.col[i]) return a.col[i]<b.col[i];
        return 0;
    }
}a[410],a1,a2,a3,a4;
map<node,int>mp;
void insert(node x,int v){for (int i=0;i<4;i++,x=x.nxt()) mp[x]+=v;}

ll ans,re;
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        scanf("%d%d%d%d",&a[i].col[0],&a[i].col[1],&a[i].col[2],&a[i].col[3]);    
        insert(a[i],1);    
    }
    for (int i=1;i<=n;i++)
    {
        insert(a[i],-1);
        for (int j=i+1;j<=n;j++)
        {
            insert(a[j],-1);
            for (int t=0;t<4;t++)
            {
                a1=node{a[j].col[1],a[i].col[0],a[i].col[3],a[j].col[2]};
                a2=node{a[i].col[1],a[j].col[0],a[j].col[3],a[i].col[2]};
                a3=node{a[j].col[1],a[j].col[0],a[i].col[1],a[i].col[0]};
                a4=node{a[i].col[3],a[i].col[2],a[j].col[3],a[j].col[2]};
                a[j]=a[j].nxt();                
                if (mp[a1]==0||mp[a2]==0||mp[a3]==0||mp[a4]==0) continue;
                re=1;
                re*=mp[a1];insert(a1,-1);
                re*=mp[a2];insert(a2,-1);
                re*=mp[a3];insert(a3,-1);
                re*=mp[a4];
                insert(a1,1);insert(a2,1);insert(a3,1);
                ans+=re;

            }
            insert(a[j],1);
        }
    }
    cout<<ans<<endl;
    return 0;
}