#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];

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;
}

vector<int> getBest(vector<int> cl)
{
    vector<int> bst = cl;
    for(int j = 0; j < 4; j++)
    {
        cl.insert(cl.begin(), cl.back());
        cl.pop_back();
        if(bst > cl)    bst = cl;
    }
    return bst;
}

int rotateCount(vector<int> cl)
{
    LL h = cl[0] + LL(1e3) * cl[1] + LL(1e6) * cl[2] + LL(1e9) * cl[3];
    int cnt = 0;
    for(int j = 0; j < 4; j++)
    {
        cl.insert(cl.begin(), cl.back());
        cl.pop_back();
        LL h2 = cl[0] + LL(1e3) * cl[1] + LL(1e6) * cl[2] + LL(1e9) * cl[3];
        cnt += (h == h2);
    }
    return cnt;
}

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++)
    {
        vector<int> cl;
        for(int j = 0; j < 4; j++)
        {
            int x; scanf("%d", &x);
            cl.push_back(x);
        }

        vector<int> bst = getBest(cl);
        for(int j = 0; j < 4; j++)  c[i][j] = bst[j];

        hsh[i] = bst[0] + LL(1e3) * bst[1] + LL(1e6) * bst[2] + LL(1e9) * bst[3];
        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++)
                {
                    vector<int> cl;
                    cl.push_back(c[i][k]);
                    cl.push_back(c[j][(k + d) % 4]);
                    cl.push_back(c[j][(k + d + 1) % 4]);
                    cl.push_back(c[i][(k + 1) % 4]);

                    vector<int> bst = getBest(cl);
                    LL h = bst[0] + LL(1e3) * bst[1] + LL(1e6) * bst[2] + LL(1e9) * bst[3];

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

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

                    cnt = rotateCount(bst);
                    sol = (1LL * sol * cnt);

                    lst = k;
                }

                ans += sol;

                for(int k = 0; k <= lst; k++)
                {
                    vector<int> cl;
                    cl.push_back(c[i][k]);
                    cl.push_back(c[j][(k + d) % 4]);
                    cl.push_back(c[j][(k + d + 1) % 4]);
                    cl.push_back(c[i][(k + 1) % 4]);

                    vector<int> bst = getBest(cl);
                    LL h = bst[0] + LL(1e3) * bst[1] + LL(1e6) * bst[2] + LL(1e9) * bst[3];

                    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