#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
unordered_map < ll, int > mp;
int n;
const int maxN = 405;
vector < int > c[maxN];
void transform(vector < int >& a) {
    int ans[4];
    for (int j = 0; j < 4; j++) {
        ans[j] = a[j];
    }
    for (int i = 1; i < 4; i++) {
        int b[4];
        for (int j = 0; j < 4; j++) {
            b[j] = a[(i + j) % 4];
        }
        for (int j = 0; j < 4; j++) {
            if (ans[j] != b[j]) {
                if (ans[j] > b[j]) {
                    for (int k = 0; k < 4; k++) {
                        ans[k] = b[k];
                    }
                }
                break;
            }
        }
    }
    for (int j = 0; j < 4; j++) {
        a[j] = ans[j];
    }
}
ll val[maxN];
int cnt[maxN];
int get(vector < int >& a) {
    int f = 0;
    for (int j = 0; j < 4; j++) {
        bool ok = true;
        for (int p = 0; p < 4; p++) {
            if (a[p] != a[(j + p) % 4]) {
                ok = false;
                break;
            }
        }
        if (ok) f++;
    }
    assert(f >= 1);
    return f;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
//    n = 400;
    for (int i = 0; i < n; i++) {
        c[i].resize(4);
        for (int j = 0; j < 4; j++) {
            cin >> c[i][j];
//            c[i][j] = 0;
        }
        transform(c[i]);
        val[i] = 0;
        for (int j = 0; j < 4; j++) {
            val[i] = 1000 * val[i] + c[i][j];
        }
        mp[val[i]]++;
    }
    ll ans = 0;
    for (int first = 0; first < n; first++) {
        for (int rot1 = 0; rot1 < 1; rot1++) {
            for (int second = first + 1; second < n; second++) {
//                if (first == second) continue;
                for (int rot2 = 0; rot2 < 4; rot2++) {
                    vector < int > f1, f2;
                    for (int p = 0; p < 4; p++) {
                        f1.emplace_back(c[first][(p + rot1) % 4]);
                        f2.emplace_back(c[second][(p + rot2) % 4]);
                    }
                    vector < vector < int > > r;
                    r.push_back({f1[0], f2[1], f2[0], f1[1]});
                    r.push_back({f1[1], f2[0], f2[3], f1[2]});
                    r.push_back({f2[3], f2[2], f1[3], f1[2]});
                    r.push_back({f2[1], f1[0], f1[3], f2[2]});
                    for (int p = 0; p < 4; p++) {
                        transform(r[p]);
                    }
                    ll ways = 1;
                    for (int gg = 0; gg < 4; gg++) {
                        bool ok = true;
                        for (int vv = 0; vv < gg; vv++) {
                            if (r[vv] == r[gg]) {
                                ok = false;
                                break;
                            }
                        }
                        if (!ok) continue;
                        int z = 1;
                        for (int vv = gg + 1; vv < 4; vv++) {
                            if (r[vv] == r[gg]) z++;
                        }
                        int per = get(r[gg]);
                        ll his_val = 0;
                        for (int al = 0; al < 4; al++) {
                            his_val = 1000 * his_val + r[gg][al];
                        }
                        if (!mp.count(his_val)) {
                            ways = 0;
                            break;
                        }
                        int total = mp[his_val];
                        total *= per;
                        if (his_val == val[first]) total -= per;
                        if (his_val == val[second]) total -= per;
                        for (int m = 1; m <= z; m++) {
                            int cnt_now = (total - (m - 1) * per);
                            cnt_now = max(cnt_now, 0);
                            ways *= cnt_now;
                        }
                    }
                    ans += ways;
                }
            }
        }
    }
    assert(ans % 3 == 0);
    cout << ans / 3;
    return 0;
}

Measured memory_bytes: 256