#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, a, b, c, d, x[1000][2][2], Nc, Cl[1000], j, k, xx[2][2], cod, ii,
      jj, Nv, y[2][2];
  string s;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a >> b;
    x[i - 1][0][0] = a / 10;
    x[i - 1][0][1] = a % 10;
    x[i - 1][1][0] = b / 10;
    x[i - 1][1][1] = b % 10;
    if (i < n) cin >> s;
  }
  Nc = 0;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= Nc; j++) {
      k = Cl[j - 1];
      xx[0][0] = x[k - 1][0][0];
      xx[0][1] = x[k - 1][0][1];
      xx[1][0] = x[k - 1][1][0];
      xx[1][1] = x[k - 1][1][1];
      Nv = 0;
    aaa:
      Nv++;
      cod = 0;
      if (Nv == 5) goto bbb;
      for (ii = 0; ii <= 1; ii++)
        for (jj = 0; jj <= 1; jj++)
          if (x[i - 1][ii][jj] != xx[ii][jj]) cod = 1;
      if (cod == 0) break;
      y[0][0] = xx[1][0];
      y[0][1] = xx[0][0];
      y[1][1] = xx[0][1];
      y[1][0] = xx[1][1];
      for (ii = 0; ii <= 1; ii++)
        for (jj = 0; jj <= 1; jj++) xx[ii][jj] = y[ii][jj];
      goto aaa;
    bbb:;
    }
    if (j > Nc) {
      Nc++;
      Cl[Nc - 1] = i;
    }
  }
  cout << Nc;
  return 0;
}
