#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

template <typename T>
auto make_vector_impl(size_t sz, T t) {return std::vector<T>(sz, t);}

template <size_t N, typename T, typename U, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz, U u) {return make_vector_impl(sz, T(u));}

template <size_t N, typename T, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz) {return std::vector<T>(sz);}

template <size_t N, typename T, typename... Args, std::enable_if_t<N != 1, std::nullptr_t> = nullptr>
auto make_vector(size_t a, Args... args) {return make_vector_impl(a, make_vector<N - 1, T>(args...));}

template <typename T, typename Size_t>
auto& at(T& t, Size_t i) {return t.at(i);}

template <typename T, typename Size_t, typename... Args>
auto& at(T& t, Size_t i, Args... args) {return at(t.at(i), args...);}

template < typename Container, typename Value = typename Container::value_type >
std::istream& operator>> (std::istream& is, Container& v) {
  for (auto & x : v) is >> x;
  return is;
}

template < typename Container, typename Value = typename Container::value_type >
std::ostream& operator<< (std::ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template <typename T, typename U>
std::ostream& operator<< (std::ostream& os, const std::pair<T, U>& pair)
  { return os << "(" << pair.first << "," << pair.second << ")"; }

template <typename T, typename U>
std::istream& operator>> (std::iostream& is, std::pair<T, U>& pair)
  { return is >> pair.first >> pair.second; }

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  auto data = make_vector< 2, int >(n, 4);
  std::cin >> data;
  auto multiplicity = [&] (auto a) {
    if (a.at(0) != a.at(2) || a.at(1) != a.at(3))
      { return 1; }
    if (a.at(0) != a.at(1))
      { return 2;}
    return 4;
  };
  auto power = [&] (auto x, auto y) {
    auto ret = 1LL;
    loop(y) ret *= x;
    return ret;
  };
  auto normalized = [&] (auto a) {
    auto z = a;
    loop(3) {
      std::rotate(a.begin(), a.begin() + 1, a.end());
      cmn(z, a);
    }
    return z;
  };
  for (auto & v : data) v = normalized(v);
  std::multiset< std::vector< int > > set(data.begin(), data.end());
  auto cal = [&] (auto n, auto k) {
    if (n < k) return 0LL;
    auto ret = 1LL;
    rep(i, 0, k) ret *= (n - i);
    return ret;
  };
  lint ret = 0;
  rep(i, 0, n) rep(j, i + 1, n) {
    auto x = data.at(i);
    auto y = data.at(j);
    auto seq = std::vector< int >{1, 0, 1, 0};
    loop(4) {
      std::map< std::vector< int >, int > map;
      loop(4) {
        auto z = std::vector< int >{
          x.at(seq.at(0)), x.at(seq.at(1)),
          y.at(seq.at(2)), y.at(seq.at(3))
        };
        map[normalized(z)]++;
        for (auto & x : std::vector< std::reference_wrapper< int > >{ seq.at(0), seq.at(1) })
          { (x += 1) %= 4; }
        for (auto & x : std::vector< std::reference_wrapper< int > >{ seq.at(2), seq.at(3) })
          { (x += 3) %= 4; }
      }
      auto now = 1LL;
      for (auto p : map) {
        std::vector< int > v; int l; std::tie(v, l) = p;
        auto m = (lint)set.count(v) - (x == v) - (y == v);
        assert(m >= 0);
        now *= cal(m, l) * power(multiplicity(v)  , l);
      }
      ret += now;
      for (auto & x : std::vector< std::reference_wrapper< int > >{ seq.at(2), seq.at(3) })
        { (x += 3) %= 4; }
    }
  }
  assert(ret % 3 == 0);
  ret /= 3;
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 384