#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////
bool cmp(vector<ll> a, vector<ll> b) {
	rep(j, 4) {
		if (a[j] < b[j]) { return true; }
		if (a[j] > b[j]) { return false; }
	}
	return false;
}

ll com(ll a, ll b) {
	if (a < b) { return 0; }

	ll ret = 1;
	for (ll i = a; i >= a - b + 1; i--)ret *= i;
	
	return ret;
}

vector<ll> rotate(vector<ll> s, ll j) {
	vector<ll> ret(4);

	rep(i, 4) { ret[i] = s[(i + j) % 4]; }
	
	return ret;
}

vector<ll> normalize(vector<ll> s) {
	vector<ll> ret = s;

	rep(i, 4) { if (cmp(rotate(s, i), ret)) { ret = rotate(s, i); } }

	return ret;
}


int main() {
	ll N;
	cin >> N;

	map<vector<ll>, ll> mp;
	
	repn(i, N) {
		vector<ll> s(4);
		rep(j, 4) cin >> s[j];

		s = normalize(s);
		//cout << s << endl;
		mp[s]++;
	}

	ll ans = 0;

	for (auto p : mp)for (auto q : mp) {
		vector<vector<ll>> s(6, vector<ll>(4, 0));

		s[0] = p.first;

		

		rep(j, 4) {
			s[1] = rotate(q.first, j);

			rep(k, 4) {
				s[k + 2][0] = s[0][k];
				s[k + 2][1] = s[1][3-k];
				s[k + 2][2] = s[1][(6-k) % 4];
				s[k + 2][3] = s[0][(k + 1) % 4];
				
			}
			//rep(k, 6) cout << s[k] << " ";
			//cout << endl;
			
			rep(k, 6) { s[k] = normalize(s[k]); }

			//rep(k, 6) cout << s[k] << " ";
			//cout << endl;

			map<vector<ll>, ll> men;
			rep(k, 6) { men[s[k]]++; }

			ll count = 1;
			for (auto r : men) {
				vector<ll> u = r.first;
				if (!mp.count(u)) { count = 0; break; }
				count *= com(mp[u], men[u]);
				//cout << u <<" "<< mp[u] <<" "<< men[u] << endl;
			}
			//cout << endl;

			rep(k, 4) {
				ll c = 0;
				rep(l, 4) { if (s[k+2] == rotate(s[k+2], l)) { c++; } }
				count *= c;
			}

			ans += count;
		}
	}

	cout << ans/6 << endl;
	
}


Measured memory_bytes: 256