#include <bits/stdc++.h>
using namespace std;

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define kk(n)    ff(k, n)
#define xx(n)    ff(x, n)
#define yy(n)    ff(y, n)
#define ii(n)    ff(i, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define kkk(a, b) fff(k, a, b)
#define xxx(a, b) fff(x, a, b)
#define yyy(a, b) fff(y, a, b)
#define iii(a, b) fff(i, a, b)
#define bb begin()
#define ee end()
#define uu first
#define vv second
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#define zz(array, byte)   memset(array, byte, sizeof(array));

using LL = long long;
using DD = long double;
using pii = pair<int, int>;



const LL  INFLL  = 0x7f7f7f7f7f7f7f7fLL;
const int INFint = 0x7f7f7f7f;  //Works with memset(..).
 
     

int cs[404][4];


LL makeCanonical(int a, int b, int c, int d) {
    vector<int> colours = {a, b, c, d};

    vector<LL> ts;
    xx (4) {
        LL type = 0;
        yy (4)
            type = (type * 1000) + colours[(x+y)%4];
        ts.append(type);
    }
    sort(all(ts));
    return ts[0];
}

int main() {
    ios_base::sync_with_stdio(false);     cin.tie(NULL);
    //cout << '\n';
    cout.precision(16);
    

    int N;
    cin >> N;
    map<LL, int> typecounts;
    map<LL, int> selfsymmetries;
    vector<LL> canonical_types(N);
    ii (N) {
        cin >> cs[i][0]
            >> cs[i][1]
            >> cs[i][2]
            >> cs[i][3];
        map<LL, int> types;
        xx (4) {
            LL type = 0;
            yy (4)
                type = (type * 1000) + cs[i][(x+y)%4];
            ++types[type];
        }
        canonical_types[i] = makeCanonical(cs[i][0],
                                           cs[i][1],
                                           cs[i][2],
                                           cs[i][3]);
        ++typecounts[canonical_types[i]];
        selfsymmetries[canonical_types[i]] = 4 / len(types);
    }

    LL rr = 0;
    ii (N) {
        kkk (i+1, N) {
            ff (rotation, 4) {
                vector<LL> sought_canonical = {
                    makeCanonical(cs[k][(1+rotation)%4],
                                  cs[k][(0+rotation)%4],
                                  cs[i][1],
                                  cs[i][0]),
                    makeCanonical(cs[k][(2+rotation)%4],
                                  cs[k][(1+rotation)%4],
                                  cs[i][0],
                                  cs[i][3]),
                    makeCanonical(cs[k][(3+rotation)%4],
                                  cs[k][(2+rotation)%4],
                                  cs[i][3],
                                  cs[i][2]),
                    makeCanonical(cs[k][(0+rotation)%4],
                                  cs[k][(3+rotation)%4],
                                  cs[i][2],
                                  cs[i][1])
                };

                LL here = 1;
                map<LL, int> left;
                map<LL, int> need;
                xx (4) {
                    ++need[sought_canonical[x]];
                    if (!typecounts.count(sought_canonical[x])) {
                        here = 0;
                        break;
                    }
                    left[sought_canonical[x]] = typecounts[sought_canonical[x]];
                }
                if (!here) continue;
                --left[canonical_types[i]];
                --left[canonical_types[k]];
                fe (it, need) {
                    LL ct = it->uu;
                    int n = it->vv;
                    if (left[ct] < n) {
                        here = 0;
                        break;
                    }
                    xx (n)
                        here = (here * LL(left[ct] - x) 
                                * LL(selfsymmetries[ct]));
                }
                //printf("%d %d rotation %d: adding %d\n", i, k, rotation,
                //        int(here));
                rr += here;
            }
        }
    }

    cout << rr/3 << '\n';
    
    

    return 0;
}



Measured memory_bytes: 384