#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//
constexpr ll MOD = 1e9 + 7;
/*/
const ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion


// https://atcoder.jp/contests/arc062/submissions/6354580

map<ll, ll> symmetry;
map<ll, vll> decode;
map<ll, ll> counter;

ll encode(vll &v){
  ll t = INF;
  rep(i, 4){
    rotate(v.begin(), v.begin()+1, v.end());
    ll tmp = 0;
    rep(j, 4){
      tmp += v[j]*(1ll << (10*j));
    }
    chmin(t, tmp);
  }
  return t;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll tiles;
  rep(i, n){
    vll col(4);
    rep(j, 4){
      cin >> col[j];
    }
    // 正規化してタイルを管理
    ll t = encode(col);
    tiles.emplace_back(t);
    counter[t]++;
    decode[t] = col;
    // C4, C2 対称
    if(col[0] == col[1] && col[1] == col[2] && col[2] == col[3]){
      symmetry[t] = 4;
    }else if(col[0] == col[2] && col[1] == col[3]){
      symmetry[t] = 2;
    }else{
      symmetry[t] = 1;
    }
  }
  ll ans = 0;
  // 対面、回転　全探索
  rep(ii, n)repr(jj, ii+1, n){
    ll bottom = tiles[ii], top = tiles[jj];
    // 消費
    counter[bottom]--;
    counter[top]--;
    vll colb = decode[bottom];
    vll colt = decode[top];
    rep(rot, 4){
      rotate(colt.begin(), colt.begin()+1, colt.end());
      vll tls;
      vll t{colb[1], colb[0], colt[0], colt[3]};
      tls.emplace_back(encode(t));
      t = {colb[2], colb[1], colt[3], colt[2]};
      tls.emplace_back(encode(t));
      t = {colb[3], colb[2], colt[2], colt[1]};
      tls.emplace_back(encode(t));
      t = {colb[0], colb[3], colt[1], colt[0]};
      tls.emplace_back(encode(t));
      
      // 必要量の算出
      map<ll, ll> need;
      ll x = 1;
      for(auto&& e: tls){
        need[e]++;
      }
      for(auto&& tile: need){
        ll have = counter[tile.first];
        if(have < tile.second){
          x = 0;
          break;
        }
        // P(使用可能タイル数, 使用量)
        rep(i, tile.second){
          x *= counter[tile.first]-i;
        }
        // 対称性
        rep(i, tile.second){
          x *= symmetry[tile.first];
        }
      }
      ans += x;
    }
    counter[bottom]++;
    counter[top]++;
  }
  print(ans/3);
}


Measured memory_bytes: 20352