#include <bits/stdc++.h>
typedef struct {
  int sum, a, b, c, d;
} kubik_t;
int find(kubik_t *kubiki, int size, int a, int b, int c, int d) {
  int i;
  for (i = 0; i < size; i++) {
    if (kubiki[i].sum == (a + b + c + d)) {
      if (kubiki[i].a == a && kubiki[i].b == b && kubiki[i].c == c &&
          kubiki[i].d == d) {
        return 1;
      } else if (kubiki[i].a == b && kubiki[i].b == c && kubiki[i].c == d &&
                 kubiki[i].d == a) {
        return 1;
      } else if (kubiki[i].a == c && kubiki[i].b == d && kubiki[i].c == a &&
                 kubiki[i].d == b) {
        return 1;
      } else if (kubiki[i].a == d && kubiki[i].b == a && kubiki[i].c == b &&
                 kubiki[i].d == c) {
        return 1;
      }
    }
  }
  return 0;
}
int main() {
  int n, a, b, c, d, i, size;
  char null;
  kubik_t kubiki[1000];
  scanf("%d", &n);
  size = 0;
  for (i = 0; i < n; i++) {
    scanf("%1d%1d\n", &a, &b);
    scanf("%1d%1d\n", &d, &c);
    if (!find(kubiki, size, a, b, c, d)) {
      kubiki[size].sum = a + b + c + d;
      kubiki[size].a = a;
      kubiki[size].b = b;
      kubiki[size].c = c;
      kubiki[size].d = d;
      size++;
    }
    if (i + 1 != n) {
      scanf("%c %c\n", &null, &null);
    }
  }
  printf("%d\n", size);
  return 0;
}
