#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 1000000000;
const ll M = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

P f(ll x, ll y, ll z, ll w) {
    ll c[4] = {x, y, z, w};
    ll a[4] = {};
    rep(i, 4) {
        rep(j, 4) {
            a[i] *= 1000;
            a[i] += c[(i + j) % 4];
        }
    }
    ll ret = max(max(a[0], a[1]), max(a[2], a[3]));
    ll cnt = 0;
    rep(i, 4) if (a[i] == ret) cnt++;
    return P(ret, cnt);
}

int main() {
    int n;
    ll c[402][4];
    P A[402];
    scanf("%d", &n);
    rep(i, n) {
        rep(j, 4) { cin >> c[i][j]; }
        A[i] = f(c[i][0], c[i][1], c[i][2], c[i][3]);
    }

    map<ll, int> M;
    rep(i, n) M[A[i].fr] += A[i].sc;

    ll ret = 0;
    rep(i, n) {
        M[A[i].fr] -= A[i].sc;
        for (int j = i + 1; j < n; j++) {
            M[A[j].fr] -= A[j].sc;
            rep(k, 4) {
                P x[4];
                ll _ret = 1;
                rep(l, 4) {
                    x[l] = f(c[i][l], c[j][(k + 4 - l) % 4],
                             c[j][(k + 4 - l - 1) % 4], c[i][(l + 1) % 4]);
                    _ret *= M[x[l].fr];
                    M[x[l].fr] -= x[l].sc;
                }
                rep(l, 4) { M[x[l].fr] += x[l].sc; }
                ret += _ret;
            }
            M[A[j].fr] += A[j].sc;
        }
    }

    cout << ret;
    /* ====================================== */
    cout << endl;
    return 0;
}

Measured memory_bytes: 80128