#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

V<int> cyc(V<int> &a) {
	VV<int> cand;
	rep(j, 4) {
		V<int> vec;
		rep(k, 4) {
			vec.pb(a[(j+k)%4]);
		}
		cand.pb(vec);
	}
	return *min_element(ALL(cand));
}

int com(V<int>& v) {
	int cnt = 0;
	rep(j, 4) {
		V<int> vec;
		rep(k, 4) {
			vec.pb(v[(j+k)%4]);
		}
		if (vec == v) {
			++cnt;
		}
	}
	return cnt;
}

int main() {
	int N; cin >> N;
	VV<int> vf;

	map<V<int>, int> T, coef;

	rep(i, N) {
		V<int> a(4);
		rep(j, 4) cin >> a[j];

		auto vec = cyc(a);
		vf.pb(vec);
		++T[vec];
		dump(vec);
		coef[vec] = com(vec);
	}

	ll ans = 0;

	rep(i, N) {
		rep(j, i) {
			--T[vf[i]];
			--T[vf[j]];

			rep(k, 4) {
				int up[4], dw[4];
				rep(l, 4) {
					up[l] = vf[i][l];
					dw[l] = vf[j][(k-l+4)%4];
				}

				ll t = 1;

				VV<int> use;
				rep(l, 4) {
					V<int> vec{up[l],up[(l+3)%4],dw[(l+3)%4],dw[l]};
					vec = cyc(vec);
					use.pb(vec);
					t *= T[vec] * coef[vec];
					if (--T[vec] < 0) break;
				}
				ans += t;
				for (auto &v : use) {
					++T[v];
				}
			}

			++T[vf[i]];
			++T[vf[j]];			
		}
	}
	dump(ans);

	cout << ans / 3 << endl;

	return 0;
}