#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
//4008802802
//4008160009
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define pb push_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define forn(i, a) for(register int i=0; i<a; i++)
#define Forn(i, a) for(register int i=1; i<=a; i++)
#define memINF 127
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false)
#define lid id<<1|1
#define rid (id<<1)+2
#define mid l+r>>1
#define lson lid, l, mid
#define rson rid, mid, r

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

inline int in() 
{
    int x=0, c;
    while((uint)((c=getchar())-48)>=10) 
		if(c=='-') 
			return -in();
    do 
	{ x=(x<<3)+(x<<1)+(c^48); }
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=405;
const int mod=1e7+9;
const int MAX_H=1e5+5;

struct Hash
{
    int nex, w, s;
    ll val;
    Hash(int _n=0, int _w=0, int _s=0, ll _v=0):nex(_n), w(_w), s(_s), val(_v){}
}h[MAX<<2];

int tot, N, t, C[MAX][5], head[MAX_H];
ll res, tt;

inline void Insert(ll H, int t)
{
    int fr=H/mod, id=head[fr];
    while(id&&h[id].val!=H)
        id=h[id].nex;
    if(id)
    {
        h[id].w+=t;
        return;
    }
    id=++tot, h[id].nex=head[fr], h[id].val=H, head[fr]=id, h[id].w=t;
    h[id].s=H/(ll)1e6==H%(ll)1e6?(H/(ll)1e9==H%(ll)1e3?4:2):1;
}

inline int Find(ll H)
{
    int fr=H/mod, id=head[fr];
    while(id&&h[id].val!=H)
        id=h[id].nex;
    return h[id].w*h[id].s;
}

inline ll Get_Hash(int *t, int turn)
{
    ll ret=0;
    forn(i, 4)
        ret=ret*1000+t[(i+turn)&3];
    return ret;
}

inline void Add(ll H, int t)
{
    ll tmp[4];
    forn(i, 4)
        tmp[i]=H, H=H/1000+H%1000*1000000000;
    sort(tmp, tmp+4);
    int ptr=unique(tmp, tmp+4)-tmp;
    forn(i, ptr)
        Insert(tmp[i], t);
}

inline void Add(int *T, int t)
{
    Add(Get_Hash(T, 0), t);
}

int main()
{
    N=in();
    forn(i, N)
    {
        forn(j, 4)
            C[i][j]=in();
        Add(C[i], 1);
    }
    forn(i, N)
    {
        Add(C[i], -1);
        for(int j=i+1; j<N; ++j)
        {
            Add(C[j], -1);
            reverse(C[j], C[j]+4);
            
            forn(k, 4)
            {
                tt=1;
                for(t=0; t<4; ++t)
                {
                    ll h=((C[j][(k+t)&3]*1000LL+C[j][(k+t+1)&3])*1000+C[i][(t+1)&3])*(ll)1000+C[i][t];
                    tt*=Find(h);
                    if(!tt)
                        break;
					Add(h, -1);
                }
                while(t--)
                {
                    ll h=((C[j][(k+t)&3]*1000LL+C[j][(k+t+1)&3])*(ll)1000+C[i][(t+1)&3])*(ll)1000+C[i][t];
                    Add(h, 1);
                }
                res+=tt;
            }
            reverse(C[j], C[j]+4);
            Add(C[j], 1);
        }
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 640