#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
int c[400][4];
LL h[400];
int e[5], f[5];
int sides[4][4];
LL sh[4];
bool used[4];
map<LL, int> cnt;

LL getHash(int *a) {
    LL h = 0;
    forn(i, 4) {
        h <<= 10;
        h |= a[i];
    }
    return h;
}

void lexMin(int *a) {
    int cur[4];
    forn(i, 4) cur[i] = a[i];
    forn(i, 3) {
        int tmp = a[0];
        forn(j, 3) a[j] = a[j + 1];
        a[3] = tmp;
        bool ok = false;
        forn(j, 4) if (a[j] != cur[j]) {
            ok = a[j] < cur[j];
            break;
        }
        if (ok) {
            forn(j, 4) {
                cur[j] = a[j];
            }
        }
    }
    forn(i, 4) a[i] = cur[i];
}

int calcSameRots(int *a) {
    int same = 1;
    int b[4];
    forn(i, 4) {
        b[i] = a[i];
    }
    forn(i, 3) {
        int tmp = b[0];
        forn(j, 3) b[j] = b[j + 1];
        b[3] = tmp;
        bool ok = true;
        forn(j, 4) if (b[j] != a[j]) {
            ok = false;
            break;
        }
        if (ok) {
            ++same;
        }
    }
    return same;
}

LL C[1111][6];
LL fac[10] = {};

int main() {
    //freopen("input.txt", "r", stdin);
    fac[0] = 1;
    for (int i = 1; i < 10; ++i) {
        fac[i] = fac[i - 1] * i;
    }
    forn(i, 6) C[0][i] = 0;
    C[0][0] = 1;
    for (int i = 1; i < 1111; ++i) {
        C[i][0] = 1;
        for (int j = 1; j < 6; ++j) {
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
        }
    }
    ios_base::sync_with_stdio(false);
    cin >> n;
    forn(i, n) forn(j, 4) {
        cin >> c[i][j];
    }
    /*cout << LL(9e18) << endl;
    forn(i, n) forn(j, 4) {
        c[i][j] = 0;
    }*/
    forn(i, n) {
        lexMin(c[i]);
        h[i] = getHash(c[i]);
    }
    LL ans = 0;
    forn(i, n) {
        forn(z, 4) {
            e[z] = c[i][z];
        }
        e[4] = e[0];
        forn(j, i) {
            --cnt[h[j]];
            forn(k, 4) {
                forn(z, 4) {
                    f[z] = c[j][(z + k) % 4];
                }
                reverse(f, f + 4);
                f[4] = f[0];
                forn(z, 4) {
                    sides[z][0] = e[z + 1];
                    sides[z][1] = e[z];
                    sides[z][2] = f[z];
                    sides[z][3] = f[z + 1];
                    lexMin(sides[z]);
                    sh[z] = getHash(sides[z]);
                }
                forn(z, 4) {
                    used[z] = false;
                }
                LL cur = 1;
                forn(z, 4) {
                    if (used[z]) {
                        continue;
                    }
                    used[z] = true;
                    int same = 1;
                    for (int y = z + 1; y < 4; ++y) {
                        if (sh[z] == sh[y]) {
                            ++same;
                            used[y] = true;
                        }
                    }
                    cur *= C[cnt[sh[z]]][same] * fac[same];
                }
                forn(z, 4) {
                    cur *= calcSameRots(sides[z]);
                }
                ans += cur;
            }
            ++cnt[h[j]];
        }
        ++cnt[h[i]];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 80128