#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct kek{
    short v[4];
}a[404];
bool operator<(const kek&x,const kek&y){
    forn(i,4){
        if(x.v[i]<y.v[i])return 1;
        if(x.v[i]>y.v[i])return 0;
    }
    return 0;
}
bool operator==(const kek&x,const kek&y){
    forn(i,4){
        if(x.v[i]!=y.v[i])return 0;
    }
    return 1;
}
int32_t main(){
    int n;
    cin>>n;
    map<kek,int> cnt;
    forn(i,n){
        forn(j,4)cin>>a[i].v[j];
        kek mn;
        forn(q,4)mn.v[q]=a[i].v[q];
        forn(it,4){
            if(a[i]<mn)forn(q,4)mn.v[q]=a[i].v[q];
            rotate(a[i].v,a[i].v+1,a[i].v+4);
        }
        forn(it,4){
            if(mn==a[i])cnt[mn]++;
            rotate(a[i].v,a[i].v+1,a[i].v+4);
        }
        forn(q,4)a[i].v[q]=mn.v[q];        
    }
    int ans=0;
    forn(i,n){
        forn(j,n){
            if(i==j)continue;
            short dal[4];
            forn(x,4)dal[x]=a[j].v[x];
            forn(rotzad,4){
                map<kek,pii> g;
                forn(side,4){
                    kek need;
                    need.v[0]=a[i].v[side];
                    need.v[1]=dal[(4-side)&3];
                    need.v[2]=dal[(4-((side+1)&3))&3];
                    need.v[3]=a[i].v[(side+1)&3];
                    kek mn;
                    forn(q,4)mn.v[q]=need.v[q];
                    forn(tmp,4){
                        if(need<mn)forn(q,4)mn.v[q]=need.v[q];
                        rotate(need.v,need.v+1,need.v+4);
                    }
                    int val=cnt[mn];
                    forn(tmp,4){
                        val-=a[i]==mn;
                        val-=a[j]==mn;
                        rotate(mn.v,mn.v+1,mn.v+4);
                    }
                    g[mn].f++;
                    g[mn].s=val;
                }
                int cur=1;
                for(auto&p:g){
                    kek kok;
                    forn(q,4)kok.v[q]=p.f.v[q];
                    int r=0;
                    forn(q,4){
                        if(kok==p.f)r++;
                        rotate(kok.v,kok.v+1,kok.v+4);
                    }
                    forn(q,p.s.f)cur*=p.s.s-q*r;
                }
                ans+=cur;
                rotate(dal,dal+1,dal+4);
            }
        }
    }
    cout<<ans/6<<'\n';

    return 0;
}

Measured memory_bytes: 83392