#include <bits/stdc++.h>
using namespace std;

int n;
map<array<int, 4>, int> mp;

int same(array<int, 4> a, array<int, 4> b) {
  int res = 0;
  if (a == array<int, 4>{b[0], b[1], b[2], b[3]}) res++;
  if (a == array<int, 4>{b[1], b[2], b[3], b[0]}) res++;
  if (a == array<int, 4>{b[2], b[3], b[0], b[1]}) res++;
  if (a == array<int, 4>{b[3], b[0], b[1], b[2]}) res++;
  return res;
}

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

  cin >> n;
  vector<array<int, 4>> up;
  long long ans = 0;

  for (int i = 0; i < n; i++) {
    array<int, 4> c;
    for (int j = 0; j < 4; j++) {
      cin >> c[j];
    }

    for (auto &d : up) {
      array<int, 4> w = {d[0], d[3], c[0], c[3]};
      array<int, 4> x = {d[3], d[2], c[1], c[0]};
      array<int, 4> y = {d[2], d[1], c[2], c[1]};
      array<int, 4> z = {d[1], d[0], c[3], c[2]};

      long long cur = 1;
      cur *= 1ll * mp[w] - same(d, w);
      cur *= 1ll * mp[x] - same(w, x) - same(d, x);
      cur *= 1ll * mp[y] - same(w, y) - same(x, y) - same(d, y);
      cur *= 1ll * mp[z] - same(w, z) - same(x, z) - same(y, z) - same(d, z);
      ans += cur;
    }

    up.push_back({c[0], c[1], c[2], c[3]}); mp[up.back()]++;
    up.push_back({c[1], c[2], c[3], c[0]}); mp[up.back()]++;
    up.push_back({c[2], c[3], c[0], c[1]}); mp[up.back()]++;
    up.push_back({c[3], c[0], c[1], c[2]}); mp[up.back()]++;
  }

  cout << ans << "\n";
  return 0;

}
