#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl

//-----
const int N = 4e2 + 7;
ll nxt(ll d) { return d / 1000 + (d % 1000) * 1000000000; }
unordered_map<ll, int > cnt;
void chg(ll d, int v) { rep(i, 0, 4) { cnt[d] += v; d = nxt(d); } }

ll v2d(vi v) { ll d = 0; rep(i, 0, 4) d = d * 1000 + v[i]; return d; }
vi d2v(ll d) { vi v(4); per(i, 0, 4) v[i] = d % 1000, d /= 1000; return v; }

int n;
ll c[N];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> n; 
	rep(i, 0, n) {
		vi v(4); rep(j, 0, 4) cin >> v[j];
		c[i] = v2d(v);
		chg(c[i], 1);
	}
	ll ans = 0, rel = 0;
	rep(i, 0, n) {
		chg(c[i], -1);
		ll ci = c[i];
		vi a = d2v(ci);
		rep(j, 0, n) if (j != i) {
			chg(c[j], -1);
			ll cj = c[j];
			rep(dj, 0, 4) {
				vi b = d2v(cj); cj = nxt(cj);
				ll up = v2d({b[1], b[0], a[1], a[0]});
				ll dn = v2d({a[3], a[2], b[3], b[2]});
				ll lf = v2d({b[1], a[0], a[3], b[2]});
				ll rt = v2d({a[1], b[0], b[3], a[2]});
				ll tmp = 1;
				tmp *= cnt[up]; chg(up, -1);
				tmp *= cnt[dn]; chg(dn, -1);
				tmp *= cnt[lf]; chg(lf, -1);
				tmp *= cnt[rt]; 
				ans += tmp;
				ll q = ans / 6;
				rel += q;
				ans -= q * 6;
				chg(lf, 1);
				chg(dn, 1);
				chg(up, 1);
			}
			chg(c[j], 1);
		}
		chg(c[i], 1);
	}
	cout << rel;
	return 0;
}