#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modpow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 0;
int n, c[400][4], d[4];
ll ser(ll c1, ll c2, ll c3, ll c4){
  return ((c1 * 1000ll + c2) * 1000ll + c3) * 1000 + c4;
}
ll norm(ll c1, ll c2, ll c3, ll c4){
  ll ret = -1;
  maxs(ret, ser(c1, c2, c3, c4));
  maxs(ret, ser(c2, c3, c4, c1));
  maxs(ret, ser(c3, c4, c1, c2));
  maxs(ret, ser(c4, c1, c2, c3));
  return ret;
}
int same(ll c1, ll c2, ll c3, ll c4){
  int ret = 1;
  if(c1==c3&&c2==c4){
    ret=2;
    if(c1==c2) ret=4;
  }
  return ret;
}
int same(ll s){
  ll c1 = s / 1000000000ll % 1000;
  ll c2 = s / 1000000ll    % 1000;
  ll c3 = s / 1000ll       % 1000;
  ll c4 = s / 1ll          % 1000;
  return same(c1, c2, c3, c4);
}
ll perm(int a, int b){
  ll ret = 1;
  FOR(i, 0, b) ret *= a-i;
  return ret;
}
map<ll, int> cnt;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    FOR(j, 0, 4) cin >> c[i][j];
    cnt[norm(c[i][0], c[i][1], c[i][2], c[i][3])]++;
  }
  ll ans = 0;
  FOR(i, 0, n)FOR(j, 0, n)if(i!=j)FOR(k, 0, 4){
    cnt[norm(c[i][0], c[i][1], c[i][2], c[i][3])]--;
    cnt[norm(c[j][0], c[j][1], c[j][2], c[j][3])]--;
    FOR(l, 0, 4) d[l] = c[j][(l+k)%4];
    map<ll, int> t;
    t[norm(c[i][1], c[i][0], d[1], d[0])]++;
    t[norm(c[i][2], c[i][1], d[0], d[3])]++;
    t[norm(c[i][3], c[i][2], d[3], d[2])]++;
    t[norm(c[i][0], c[i][3], d[2], d[1])]++;
    ll cc = 1;
    each(itr, t) cc *= perm(cnt[itr->fi], itr->se);
    cc *= same(c[i][1], c[i][0], d[1], d[0]);
    cc *= same(c[i][2], c[i][1], d[0], d[3]);
    cc *= same(c[i][3], c[i][2], d[3], d[2]);
    cc *= same(c[i][0], c[i][3], d[2], d[1]);
    ans += cc;
    cnt[norm(c[i][0], c[i][1], c[i][2], c[i][3])]++;
    cnt[norm(c[j][0], c[j][1], c[j][2], c[j][3])]++;
  }
  cout << ans/6 << endl;
  return 0;
}

Measured memory_bytes: 80128