#include <bits/stdc++.h>
using namespace std;
struct amuletstruct {
  char a, b, c, d;
  int cnt;
};
bool isequal(amuletstruct t1, amuletstruct t2) {
  return (
      ((t1.a == t2.a) && (t1.b == t2.b) && (t1.c == t2.c) && (t1.d == t2.d)) ||
      ((t1.a == t2.c) && (t1.b == t2.a) && (t1.c == t2.d) && (t1.d == t2.b)) ||
      ((t1.a == t2.d) && (t1.b == t2.c) && (t1.c == t2.b) && (t1.d == t2.a)) ||
      ((t1.a == t2.b) && (t1.b == t2.d) && (t1.c == t2.a) && (t1.d == t2.c)));
}
int main() {
  int n, a;
  char star[10];
  int i = 0, j = 0, KindCount = 0;
  cin >> n;
  amuletstruct *tArray = new amuletstruct[n];
  for (i = 0; i < n; i++) {
    cin >> a;
    tArray[i].a = a / 10;
    tArray[i].b = a % 10;
    cin >> a;
    tArray[i].c = a / 10;
    tArray[i].d = a % 10;
    tArray[i].cnt = 0;
    if (i < n - 1) cin >> star;
  }
  tArray[0].cnt++;
  for (i = 0; i < n; i++)
    for (j = 0; j < i; j++) {
      if (tArray[j].cnt == -1) continue;
      if (isequal(tArray[j], tArray[i])) {
        tArray[j].cnt++;
        tArray[i].cnt = -1;
        break;
      } else
        tArray[i].cnt++;
    }
  for (i = 0; i < n; i++)
    if (tArray[i].cnt > 0) KindCount++;
  cout << KindCount << endl;
  return 0;
}
