#include <bits/stdc++.h>
using namespace std;
struct data {
  int a;
  int b;
  int c;
  int d;
} dice[1005];
int n;
int pile = 0;
bool found;
data new_dice;
char one[3], two[3];
bool check(data i, data j) {
  bool same = false;
  int ar[10];
  ar[0] = ar[4] = i.a;
  ar[1] = ar[5] = i.b;
  ar[2] = ar[6] = i.c;
  ar[3] = ar[7] = i.d;
  for (int t = 0; t < 4; t++) {
    if (ar[t] == j.a && ar[t + 1] == j.b && ar[t + 2] == j.c &&
        ar[t + 3] == j.d) {
      same = true;
      break;
    }
  }
  return same;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", one);
    if (one[0] != '*')
      scanf("%s", two);
    else {
      i--;
      continue;
    }
    new_dice.a = one[0] - 48;
    new_dice.b = one[1] - 48;
    new_dice.c = two[1] - 48;
    new_dice.d = two[0] - 48;
    found = false;
    for (int j = 0; j < pile; j++) {
      if (check(new_dice, dice[j])) {
        found = true;
        break;
      }
    }
    if (!found) {
      dice[pile] = new_dice;
      pile++;
    }
  }
  printf("%d\n", pile);
}
