#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

typedef long long LL;

const int mod = 1e9 + 7;

int N;
int c[405][4];
LL hsh[405];

LL coef[] = {1LL, LL(1e3), LL(1e6), LL(1e9)};

unordered_map<LL, int> mp;

int power(int x, int y)
{
    if(y <= 0)  return 1;
    int ans = power( (1LL * x * x) % mod, y >> 1 );
    if(y & 1)   ans = (1LL * ans * x) % mod;
    return ans;
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d", &N);
    for(int i = 1; i <= N; i++)
    {
        int cl[4];
        for(int j = 0; j < 4; j++)  scanf("%d", &cl[j]);

        LL h = 1LL << 60;
        int cnt = 0, id = -1;
        for(int i = 0; i < 4; i++)
        {
            LL hh = cl[i] + LL(1e3) * cl[(i + 1) & 3] + LL(1e6) * cl[(i + 2) & 3] + LL(1e9) * cl[(i + 3) & 3];
            if(h == hh) cnt++;
            else if(h > hh) { h = hh; cnt = 1; id = i; }
        }

        for(int j = 0; j < 4; j++)  c[i][j] = cl[(j + id) & 3];

        hsh[i] = h;
        mp[ hsh[i] ]++;
    }

    LL ans = 0;
    for(int i = 1; i < N; i++)
        for(int j = i + 1; j <= N; j++)
            for(int d = 0; d < 4; d++)
            {
                mp[ hsh[i] ]--; mp[ hsh[j] ]--;
                swap(c[j][1], c[j][3]);

                LL sol = 1; int lst = -1;
                for(int k = 0; k < 4; k++)
                {
                    int cl[4];
                    cl[0] = (c[i][k]);
                    cl[1] = (c[j][(k + d) & 3]);
                    cl[2] = (c[j][(k + d + 1) & 3]);
                    cl[3] = (c[i][(k + 1) & 3]);

                    LL h = 1LL << 60;
                    int cnt = 0;
                    for(int i = 0; i < 4; i++)
                    {
                        LL hh = cl[i] + LL(1e3) * cl[(i + 1) & 3] + LL(1e6) * cl[(i + 2) & 3] + LL(1e9) * cl[(i + 3) & 3];
                        if(h == hh) cnt++;
                        else if(h > hh) { h = hh; cnt = 1; }
                    }

                    if(!mp.count(h)) { sol = 0; break; }
                    int nr = mp[h];
                    if(nr <= 0) { sol = 0; break; }

                    mp[h]--;
                    sol = (1LL * sol * nr * cnt);

                    lst = k;
                }

                ans += sol;

                for(int k = 0; k <= lst; k++)
                {
                    int cl[4];
                    cl[0] = (c[i][k]);
                    cl[1] = (c[j][(k + d) & 3]);
                    cl[2] = (c[j][(k + d + 1) & 3]);
                    cl[3] = (c[i][(k + 1) & 3]);

                    LL h = 1LL << 60;
                    int cnt = 0;
                    for(int i = 0; i < 4; i++)
                    {
                        LL hh = cl[i] + LL(1e3) * cl[(i + 1) & 3] + LL(1e6) * cl[(i + 2) & 3] + LL(1e9) * cl[(i + 3) & 3];
                        if(h == hh) cnt++;
                        else if(h > hh) { h = hh; cnt = 1; }
                    }

                    mp[h]++;
                }

                swap(c[j][1], c[j][3]);
                mp[ hsh[i] ]++; mp[ hsh[j] ]++;
            }

    ans /= 3;

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

    return 0;
}


Measured memory_bytes: 256