#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[404][4] = {};
    ll z = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) for (int j = 0; j < 4; j++) cin >> a[i][j];
    for (int i = 1; i <= n; i++) {
        map<pair<pii, pii>, ll> p;
        for (int j = i + 1; j <= n; j++) {
            for (int k = 0; k < 4; k++) {
              	if (p[{{a[j][(k + 0) % 4], a[j][(k + 1) % 4]}, {a[j][(k + 2) % 4], a[j][(k + 3) % 4]}}]) {
                    z += p[{{a[j][(k + 0) % 4], a[j][(k + 1) % 4]}, {a[j][(k + 2) % 4], a[j][(k + 3) % 4]}}];
                    continue;
                }
                int c[4] = {}, b[4][4] = {{a[i][1], a[i][0], a[j][(k + 0) % 4], a[j][(k + 3) % 4]}, {a[i][2], a[i][1], a[j][(k + 3) % 4], a[j][(k + 2) % 4]}, {a[i][3], a[i][2], a[j][(k + 2) % 4], a[j][(k + 1) % 4]}, {a[i][0], a[i][3], a[j][(k + 1) % 4], a[j][(k + 0) % 4]}};
              	ll d[16] = {1};
                for (int l = i + 1; l <= n; l++) {
                  	for (int m = 0; m < 4; m++) {
                      	c[m] = 0;
                        if (a[l][0] == b[m][0] && a[l][1] == b[m][1] && a[l][2] == b[m][2] && a[l][3] == b[m][3]) c[m]++;
                        if (a[l][0] == b[m][1] && a[l][1] == b[m][2] && a[l][2] == b[m][3] && a[l][3] == b[m][0]) c[m]++;
                        if (a[l][0] == b[m][2] && a[l][1] == b[m][3] && a[l][2] == b[m][0] && a[l][3] == b[m][1]) c[m]++;
                        if (a[l][0] == b[m][3] && a[l][1] == b[m][0] && a[l][2] == b[m][1] && a[l][3] == b[m][2]) c[m]++;
                    }
                  	if (l == j) continue;
                    d[15] += c[0] * d[14];
                    d[15] += c[1] * d[13];
                    d[15] += c[2] * d[11];
                    d[15] += c[3] * d[7];
                    d[14] += c[1] * d[12];
                    d[14] += c[2] * d[10];
                    d[14] += c[3] * d[6];
                    d[13] += c[0] * d[12];
                    d[13] += c[2] * d[9];
                    d[13] += c[3] * d[5];
                    d[12] += c[2] * d[8];
                    d[12] += c[3] * d[4];
                    d[11] += c[0] * d[10];
                    d[11] += c[1] * d[9];
                    d[11] += c[3] * d[3];
                    d[10] += c[1] * d[8];
                    d[10] += c[3] * d[2];
                    d[9] += c[0] * d[8];
                    d[9] += c[3] * d[1];
                    d[8] += c[3] * d[0];
                    d[7] += c[0] * d[6];
                    d[7] += c[1] * d[5];
                    d[7] += c[2] * d[3];
                    d[6] += c[1] * d[4];
                    d[6] += c[2] * d[2];
                    d[5] += c[0] * d[4];
                    d[5] += c[2] * d[1];
                    d[4] += c[2] * d[0];
                    d[3] += c[0] * d[2];
                    d[3] += c[1] * d[1];
                    d[2] += c[1] * d[0];
                    d[1] += c[0] * d[0];
                }
              	p[{{a[j][(k + 0) % 4], a[j][(k + 1) % 4]}, {a[j][(k + 2) % 4], a[j][(k + 3) % 4]}}] = d[15];
                z += d[15];
            }
        }
    }
    cout << z;
}



Measured memory_bytes: 384