#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int f_min(int x, int y) { return x < y ? x : y; }
int f_max(int x, int y) { return x > y ? x : y; }
void f_swap(int &x, int &y) {
  int t;
  t = x, x = y, y = t;
}
int f_abs(int x) { return x > 0 ? x : -x; }
int f(int a[], int b[]) {
  int i;
  for (i = 0; i < 4; i++) {
    if (a[i] == b[i])
      continue;
    else if (a[i] > b[i])
      return 1;
    else
      return -1;
  }
  return 0;
}
struct po {
  int a[4];
  void rever() {
    int i, j;
    int tm[4];
    int pre[4];
    for (i = 0; i < 4; i++) pre[i] = a[i];
    for (i = 0; i < 4; i++) {
      if (i == 0) continue;
      for (j = 0; j < 4; j++) tm[j] = pre[(j + 1) % 4];
      if (f(a, tm) == -1) {
        for (j = 0; j < 4; j++) a[j] = tm[j];
      }
      for (j = 0; j < 4; j++) pre[j] = tm[j];
    }
  }
  void show() {
    int i;
    for (i = 0; i < 4; i++) printf("%d ", a[i]);
    printf("\n---\n");
  }
} am[1001];
bool cmp(po x, po y) { return f(x.a, y.a) == 1; }
char tmp[44];
int main() {
  int n;
  int i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < 2; j++) {
      scanf("%s", tmp);
      if (j == 0)
        am[i].a[0] = tmp[0] - '0', am[i].a[1] = tmp[1] - '0';
      else
        am[i].a[2] = tmp[1] - '0', am[i].a[3] = tmp[0] - '0';
    }
    am[i].rever();
    if (i != n - 1) scanf("%s", tmp);
  }
  sort(am, am + n, cmp);
  int ans = 1;
  for (i = 1; i < n; i++) {
    if (f(am[i].a, am[i - 1].a) == 0) continue;
    ans++;
  }
  printf("%d\n", ans);
  return 0;
}
