#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <deque>
#include <stack>
#include <iomanip>
#include <cmath>


using namespace std;


typedef long long ll;
typedef long double ld;


const ll MOD = 1000000007ll;


ll modSum(ll a, ll b) {
  return ((a % MOD) + (b % MOD)) % MOD;
}


ll modSubtract(ll a, ll b) {
  return (((a % MOD) - (b % MOD)) + MOD + MOD) % MOD;
}


ll modProd(ll a, ll b) {
  return ((a % MOD) * (b % MOD)) % MOD;
}


ll getPowMod(ll x, ll e) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    ll tmp = getPowMod(x, e/2);
    return modProd(tmp, tmp);
  } else {
    ll tmp = getPowMod(x, e-1);
    return modProd(tmp, x);
  }
}


ll getPow(ll x, ll e) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    ll tmp = getPow(x, e/2);
    return tmp * tmp;
  } else {
    ll tmp = getPow(x, e-1);
    return tmp * x;
  }
}


ll getInverse(ll x) {
  return getPowMod(x, MOD-2);
}


bool isEven(ll x) {
  ll tmp = ((x % 2) + 2) % 2;
  return tmp == 0;
}


ll getSumOfDigitsInBase(ll n, ll b) {
  ll ret = 0;
  while (n > 0) {
    ret += n % b;
    n /= b;
  }
  return ret;
}


vector<int> getKMP(string &s) {
  int len = (int)s.size();
  vector<int> ret (len, 0);
  for (int i = 1 ; i < len ; i++) {
    int at = ret[i-1];
    while (at > 0 && s[i] != s[at]) {
      at = ret[at-1];
    }
    if (s[i] == s[at]) {
      at++;
    }
    ret[i] = at;
  }
  return ret;
}


string getSubstring(string &s, int from, int to) {
  int l = to-from+1;
  if (l <= 0) {
    return "";
  }
  return s.substr(from, l);
}

ll gcd(ll a, ll b, ll & x, ll & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}












const int MAXN = 401;


int N;
tuple<int, int, int, int> ar[MAXN];
map< tuple<int, int, int, int>, int> freq;
set< pair< int, tuple<int, int, int, int> > > seen;



void input() {
  cin >> N;
  vector<int> tmp(4);
  for (int i = 1 ; i <= N ; i++) {
    for (int j = 0 ; j < 4 ; j++) {
      cin >> tmp[j];
    }
    bool inserted = false;
    for (int j = 0 ; j < 4 ; j++) {
      rotate(tmp.begin(), tmp.begin()+1, tmp.end());
      if (freq.find({tmp[0], tmp[1], tmp[2], tmp[3]}) != freq.end()) {
        inserted = true;
        freq[{tmp[0], tmp[1], tmp[2], tmp[3]}]++;
        break;
      }
    }
    if (!inserted) {
      freq[{tmp[0], tmp[1], tmp[2], tmp[3]}]++;
    }
    ar[i] = {tmp[0], tmp[1], tmp[2], tmp[3]};
  }
}


void preprocess() {
}


void solve() {
  ll ans = 0;
  //for (auto p : freq) {
  //  cerr << "(" << get<0>(p.first) << ", " << get<1>(p.first) << ", " << get<2>(p.first) << ", " << get<3>(p.first) << ") - " << p.second << "\n";
 // }
  vector< vector<int> > tmp(4, vector<int>(4));
  for (int i = 1 ; i <= N ; i++) {
    auto t1 = ar[i];
    freq[t1]--;
    for (int j = i+1 ; j <= N ; j++) {
      auto t2 = ar[j];
      if (seen.find({i, t2}) != seen.end()) {
        continue;
      }
      //cerr << "I = " << i << ", J = " << j << ", Ans = " << ans << "\n";
      vector<int> tmp1 = {get<0>(t1), get<1>(t1), get<2>(t1), get<3>(t1)};
      vector<int> tmp2 = {get<0>(t2), get<1>(t2), get<2>(t2), get<3>(t2)};
      reverse(tmp2.begin(), tmp2.end());
      ll origMul = freq[t2];
      freq[t2]--;

      for (int o = 0 ; o <= 3 ; o++) {
        ll mul = origMul;
        for (int s = 0 ; s <= 3 ; s++) {
          tmp[s][3] = tmp1[(s+0) % 4]; 
          tmp[s][2] = tmp1[(s+1) % 4]; 
          tmp[s][1] = tmp2[(s+o+1) % 4]; 
          tmp[s][0] = tmp2[(s+o+0) % 4]; 
          //for (auto x : tmp[s]) {
          //  cerr << x << ", "; 
         // }
          //cerr << "\n";
          ll add = 0;
          for (int r = 0 ; r < 4 ; r++) {
            rotate(tmp[s].begin(), tmp[s].begin()+1, tmp[s].end());
            auto it = freq.find({tmp[s][0], tmp[s][1], tmp[s][2], tmp[s][3]});
            if (it != freq.end()) {
              add += it->second;
            }
          }
          for (int r = 0 ; r < 4 ; r++) {
            rotate(tmp[s].begin(), tmp[s].begin()+1, tmp[s].end());
            auto it = freq.find({tmp[s][0], tmp[s][1], tmp[s][2], tmp[s][3]});
            if (it != freq.end()) {
              freq[it->first]--;
              break;
            }
          }
          //cerr << "Add = " << add << "\n";
          mul *= add;
        }
       // tuple<int, int, int, int> tup0 = {tmp[0][0], tmp[0][1], tmp[0][2], tmp[0][3]};
       // tuple<int, int, int, int> tup1 = {tmp[1][0], tmp[1][1], tmp[1][2], tmp[1][3]};
       // tuple<int, int, int, int> tup2 = {tmp[2][0], tmp[2][1], tmp[2][2], tmp[2][3]};
       // tuple<int, int, int, int> tup3 = {tmp[3][0], tmp[3][1], tmp[3][2], tmp[3][3]};
       // if (seen.find({tup0, tup2}) == seen.end() && seen.find({tup1, tup3}) == seen.end()) {
       //   if (mul > 0) {
       //     cerr << "O = " << o << "\n";
       //   }
          ans += mul;
        //}
        for (int s = 0 ; s <= 3 ; s++) {
          auto it = freq.find({tmp[s][0], tmp[s][1], tmp[s][2], tmp[s][3]});
          if (it != freq.end()) {
            freq[it->first]++;
          }
        }
      }
      freq[t2]++;
      seen.insert({i, t2});
    }
  }
  cout << ans;
}


int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);

  int T;
//  cin >> T;
  T = 1;

  for (int i = 0 ; i < T ; i++) {
    input();
    preprocess();
    solve();
  }

  return 0;
}


Measured memory_bytes: 5248