#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 1000  //check the limits, man
const ll INF = 1e12;
int v[N][4];
ll val[N];
ll hashvalue(ll a,ll b,ll c,ll d)
{
    return a*N*N*N+b*N*N+c*N+d;
}
void convert(int i)
{
    val[i]=INF;
    int k;
    rep(k,4)
        val[i]=min(val[i],hashvalue(v[i][k],v[i][(k+1)%4],v[i][(k+2)%4],v[i][(k+3)%4]));
    return ;
}
pli keyvalue(ll a,ll b,ll c,ll d)
{
    ll ar[4]={a,b,c,d};
    ll key=INF;
    int k;
    rep(k,4)
        key=min(key,hashvalue(ar[k],ar[(k+1)%4],ar[(k+2)%4],ar[(k+3)%4]));
    k=1;
    if(a==b && b==c && c==d)
        k=4;
    else if(a==c && b==d)
        k=2;
    return {key,k};
}
int main()
{
    int n,i,j,k,a,b,c,d,p,q,r,s;
    in(n);
    twod(v,i,j,n,4);
    map<ll,int> cnt;
    rep(i,n)
        convert(i),cnt[val[i]]++;
    ll ans=0,temp;
    pli key1,key2,key3,key4;
    rep(i,n)
    {
        a=v[i][0],b=v[i][1],c=v[i][2],d=v[i][3];
        cnt[val[i]]--;
        lp(j,i+1,n)
        {
            cnt[val[j]]--;
            rep(k,4)
            {
                temp=1;
                p=v[j][k],q=v[j][(k+1)%4],r=v[j][(k+2)%4],s=v[j][(k+3)%4];
                key1=keyvalue(a,q,p,b);
                key2=keyvalue(a,d,r,q);
                key3=keyvalue(d,c,s,r);
                key4=keyvalue(b,p,s,c);
                temp*=(cnt[key1.F]*key1.S);
                cnt[key1.F]--;
                temp*=(cnt[key2.F]*key2.S);
                cnt[key2.F]--;
                temp*=(cnt[key3.F]*key3.S);
                cnt[key3.F]--;
                temp*=(cnt[key4.F]*key4.S);
                cnt[key4.F]--;
                ans+=temp;
                cnt[key1.F]++;
                cnt[key2.F]++;
                cnt[key3.F]++;
                cnt[key4.F]++;
            }
            cnt[val[j]]++;
        }
    }
    llout(ans);
}



Measured memory_bytes: 80128