#include <iostream>
#include <unordered_map>
using namespace std;

long long k(long long a, long long b, long long c, long long d){
  return 1000000000*a+1000000*b+1000*c+d;
}

int comp(long long x0, long long x1, long long x2, long long x3, long long y0, long long y1, long long y2, long long y3){
  int r = 0;
  if (x0==y0 && x1==y1 && x2==y2 && x3==y3) r++;
  if (x0==y1 && x1==y2 && x2==y3 && x3==y0) r++;
  if (x0==y2 && x1==y3 && x2==y0 && x3==y1) r++;
  if (x0==y3 && x1==y0 && x2==y1 && x3==y2) r++;
  return r;
}

int main(){
  unordered_map<long long, long long> counter;
  int N; cin >> N;
  long long value;
  long long C[N][4];
  long long c1, res = 1, tot = 0;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 4; j++) cin >> C[i][j];
    for (int l = 0; l < 4; l++){
      value = k(C[i][l%4], C[i][(l+1)%4], C[i][(l+2)%4], C[i][(l+3)%4]);
      if (counter.count(value) == 0) counter[value] = 1;
      else counter[value]++;
    }
  }

  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      if (i != j){
        for (int k0 = 16; k0 < 20; k0++){
          res = 1;
          value = k(C[j][k0%4], C[j][(k0-1)%4], C[i][1], C[i][0]);
          if (counter.count(value) == 0) c1 = 0;
          else c1 = counter[value];
          c1 -= comp(C[i][0], C[i][1], C[i][2], C[i][3], C[j][k0%4], C[j][(k0-1)%4], C[i][1], C[i][0]);
          c1 -= comp(C[j][0], C[j][1], C[j][2], C[j][3], C[j][k0%4], C[j][(k0-1)%4], C[i][1], C[i][0]);
          res *= c1;

          value = k(C[j][(k0-1)%4], C[j][(k0-2)%4], C[i][2], C[i][1]);
          if (counter.count(value) == 0) c1 = 0;
          else c1 = counter[value];
          c1 -= comp(C[i][0], C[i][1], C[i][2], C[i][3], C[j][(k0-1)%4], C[j][(k0-2)%4], C[i][2], C[i][1]);
          c1 -= comp(C[j][0], C[j][1], C[j][2], C[j][3], C[j][(k0-1)%4], C[j][(k0-2)%4], C[i][2], C[i][1]);
          c1 -= comp(C[j][k0%4], C[j][(k0-1)%4], C[i][1], C[i][0], C[j][(k0-1)%4], C[j][(k0-2)%4], C[i][2], C[i][1]);
          res *= c1;

          value = k(C[j][(k0-2)%4], C[j][(k0-3)%4], C[i][3], C[i][2]);
          if (counter.count(value) == 0) c1 = 0;
          else c1 = counter[value];
          c1 -= comp(C[i][0], C[i][1], C[i][2], C[i][3], C[j][(k0-2)%4], C[j][(k0-3)%4], C[i][3], C[i][2]);
          c1 -= comp(C[j][0], C[j][1], C[j][2], C[j][3], C[j][(k0-2)%4], C[j][(k0-3)%4], C[i][3], C[i][2]);
          c1 -= comp(C[j][k0%4], C[j][(k0-1)%4], C[i][1], C[i][0], C[j][(k0-2)%4], C[j][(k0-3)%4], C[i][3], C[i][2]);
          c1 -= comp(C[j][(k0-1)%4], C[j][(k0-2)%4], C[i][2], C[i][1], C[j][(k0-2)%4], C[j][(k0-3)%4], C[i][3], C[i][2]);
          res *= c1;

          value = k(C[j][(k0-3)%4], C[j][k0%4], C[i][0], C[i][3]);
          if (counter.count(value) == 0) c1 = 0;
          else c1 = counter[value];
          c1 -= comp(C[i][0], C[i][1], C[i][2], C[i][3], C[j][(k0-3)%4], C[j][k0%4], C[i][0], C[i][3]);
          c1 -= comp(C[j][0], C[j][1], C[j][2], C[j][3], C[j][(k0-3)%4], C[j][k0%4], C[i][0], C[i][3]);
          c1 -= comp(C[j][k0%4], C[j][(k0-1)%4], C[i][1], C[i][0], C[j][(k0-3)%4], C[j][k0%4], C[i][0], C[i][3]);
          c1 -= comp(C[j][(k0-1)%4], C[j][(k0-2)%4], C[i][2], C[i][1], C[j][(k0-3)%4], C[j][k0%4], C[i][0], C[i][3]);
          c1 -= comp(C[j][(k0-2)%4], C[j][(k0-3)%4], C[i][3], C[i][2], C[j][(k0-3)%4], C[j][k0%4], C[i][0], C[i][3]);
          res *= c1;
          tot += res;
        }
      }
    }
  }
  cout << tot/6 << endl;
}


Measured memory_bytes: 384