#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n;
int a[405][4];
int id[1000][1000];
vector<P>vec;
int cnt[3333][3333];
ll calc(vector<P2>vi){
	ll ret = 1; assert(vi.size() == 4);
	bool used[4]={};
	for(int i=0;i<4;i++){
		if(used[i]) continue;
		int x[4];
		x[0]=vi[i].fi.fi,x[1]=vi[i].fi.sc,x[2]=vi[i].sc.sc,x[3]=vi[i].sc.fi;
		used[i] = true; int C = 1;
		for(int j=i+1;j<4;j++){
			if(used[j]) continue;
			int y[4];
			y[0]=vi[j].fi.fi,y[1]=vi[j].fi.sc,y[2]=vi[j].sc.sc,y[3]=vi[j].sc.fi;
			for(int k=0;k<4;k++){
				for(int l=0;l<4;l++){
					if(x[l] != y[(k+l)%4]) goto bad;
				}
				used[j] = true;
				C++; break; bad:;
			}
		}
		if(x[0] == x[1] && x[1] == x[2] && x[2] == x[3]){
			int p = cnt[id[x[0]][x[1]]][id[x[3]][x[2]]];
			
			for(int i=0;i<C;i++){
				ret *= 1LL*p;
				p -= 4;
			}
		}
		else if(x[0] == x[2] && x[1] == x[3]){
			int p = cnt[id[x[0]][x[1]]][id[x[3]][x[2]]];
			
			for(int i=0;i<C;i++){
				ret *= 1LL*p;
				p -= 2;
			}
		}
		else{
			int p = cnt[id[x[0]][x[1]]][id[x[3]][x[2]]];
			
			for(int i=0;i<C;i++){
				ret *= 1LL*p;
				p --;
			}
		}
	}
	return ret;
}
int main(){
	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++){
		for(int j=0;j<4;j++){
			vec.pb(mp(a[i][j],a[i][(j+1)%4]));
			vec.pb(mp(a[i][(j+1)%4],a[i][j]));
		}
	}
	sort(vec.begin(),vec.end()); vec.erase(unique(vec.begin(),vec.end()),vec.end());
	memset(id,-1,sizeof(id));
	for(int i=0;i<vec.size();i++){
		id[vec[i].fi][vec[i].sc] = i;
	}
	for(int i=1;i<=n;i++){
		int aa = 0,b = 1,c = 3,d = 2;
		for(int j=0;j<4;j++){
			int p = id[a[i][aa]][a[i][b]];
			int q = id[a[i][c]][a[i][d]];
			cnt[p][q]++;
			aa=(aa+1)%4;
			b=(b+1)%4;
			c=(c+1)%4;
			d=(d+1)%4;
		}
	}
	ll ret = 0;
	for(int i=1;i<=n;i++){
		int aa = 0,b = 1,c = 3,d = 2;
		for(int j=0;j<4;j++){
			int p = id[a[i][aa]][a[i][b]];
			int q = id[a[i][c]][a[i][d]];
			cnt[p][q]--;
			aa=(aa+1)%4;
			b=(b+1)%4;
			c=(c+1)%4;
			d=(d+1)%4;
		}
		for(int j=i+1;j<=n;j++){
			aa = 0,b = 1,c = 3,d = 2;
			for(int jj=0;jj<4;jj++){
				int p = id[a[j][aa]][a[j][b]];
				int q = id[a[j][c]][a[j][d]];
				cnt[p][q]--;
				aa=(aa+1)%4;
				b=(b+1)%4;
				c=(c+1)%4;
				d=(d+1)%4;
			}
			int w[4]={1,0,2,3};
			for(int k=0;k<4;k++){
				vector<P2>V; V.clear();
				V.pb(mp(mp(a[i][3],a[i][2]),mp(a[j][w[2]],a[j][w[3]])));
				V.pb(mp(mp(a[i][2],a[i][1]),mp(a[j][w[3]],a[j][w[1]])));
				V.pb(mp(mp(a[i][1],a[i][0]),mp(a[j][w[1]],a[j][w[0]])));
				V.pb(mp(mp(a[i][0],a[i][3]),mp(a[j][w[0]],a[j][w[2]])));
				ret += calc(V); 
				for(int l=0;l<4;l++) w[l] = (w[l]+1)%4;
			}
			aa = 0,b = 1,c = 3,d = 2;
			for(int jj=0;jj<4;jj++){
				int p = id[a[j][aa]][a[j][b]];
				int q = id[a[j][c]][a[j][d]];
				cnt[p][q]++;
				aa=(aa+1)%4;
				b=(b+1)%4;
				c=(c+1)%4;
				d=(d+1)%4;
			}
		}
	}
	cout << ret << endl;
}

Measured memory_bytes: 10624