#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, start, N, counter;
  char temp[3];
  bool ketemu;
  string dum, st[1001];
  scanf("%d", &N);
  if (N == 1)
    printf("1\n");
  else {
    scanf("%s", temp);
    st[0] = temp;
    scanf("%s", temp);
    st[0] = st[0] + temp[1] + temp[0];
    counter = 1;
    for (i = 1; i < N; ++i) {
      scanf("%s", temp);
      scanf("%s", temp);
      dum = temp;
      scanf("%s", temp);
      dum = dum + temp[1] + temp[0];
      ketemu = false;
      while (!ketemu) {
        for (j = 0; j < counter; ++j) {
          start = 0;
          while ((!ketemu) && (start < 4)) {
            ketemu = true;
            for (k = 0; k < 4; ++k) {
              if (st[j][(k + start) % 4] != dum[k]) {
                ketemu = false;
                break;
              }
            }
            ++start;
          }
          if (ketemu) break;
        }
        if (!ketemu) {
          st[counter] = dum;
          ++counter;
          ketemu = true;
        }
      }
    }
  }
  printf("%d\n", counter);
  return 0;
}
