#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i,n) for (int i = 0; i < n; ++i)

ll getVal(vi cs) {
    ll val = 0;
    REP (k, 4) {
        ll v = 0;
        REP (i, 4) v = v * 1000 + cs[(i+k)&3];
        val = max(val, v);
    }
    return val;
}

vi getVector(ll val) {
    vi vec(4);
    REP (k, 4) {
        vec[k] = val % 1000;
        val /= 1000;
    }
    return vec;
}

vi getVector(vi top, vi bottom, int idx) {
    vi cs(4);
    cs[0] = top[(idx+1)&3];
    cs[1] = top[idx];
    cs[2] = bottom[idx&3];
    cs[3] = bottom[(idx+1)&3];
    return cs;
}

ll rotate(ll tile) {
    ll next = tile / 1000;
    next += (tile%1000) * 1e9;
    return next;
}

const int MAX = 410;

int N;
map<ll, int> tiles;
ll C[MAX];

int main() {
    cin >> N;
    REP (k, N) {
        vi t(4);
        REP (i, 4) cin >> t[i];
        ll val = getVal(t);
        tiles[val] += 1;
        C[k] = val;
    }

    ll ans = 0;
    int count = 0;
    REP (idxT, N) {
        ll top = C[idxT];
        tiles[top] -= 1;
        vi vecT = getVector(top);
        reverse(vecT.begin(), vecT.end());
        for (int idxB = idxT+1; idxB < N; idxB++) {
            ll bottom = C[idxB];
            tiles[bottom] -= 1;

            REP (n, 4) {
                vi vecB = getVector(bottom);

                ll tmp = 1;
                vi ts(4);

                REP (idx, 4) {
                    vi side = getVector(vecT, vecB, idx);
                    ll v = getVal(side);
                    tmp *= tiles[v];
                    if (side[0] == side[2] && side[1] == side[3]) {
                        tmp *= 2;
                        if (side[0] == side[1]) tmp *= 2;
                    }
                    tiles[v] -= 1;
                    ts[idx] = v;
                }
                ans += tmp;
                REP (idx, 4) tiles[ts[idx]] += 1;

                bottom = rotate(bottom);
            }

            tiles[bottom] += 1;
        }
    }

    cout << ans << endl;
}