#include <bits/stdc++.h>
using namespace std;
bool aresame(int am[4], int newam[4]) {
  for (int i = 0; i < 4; i++) {
    bool flag = true;
    for (int j = 0; (j < 4) && (flag); j++)
      if (am[j] != newam[(j + i) % 4]) flag = false;
    if (flag) return true;
  }
  return false;
}
int main() {
  int am[1000][4], index = 0, n, newam[4];
  bool flag;
  char ne[3][3], ch[3];
  cin >> n;
  for (int i = 0; i < n; i++) {
    if (i) cin >> ch;
    cin >> ne[0] >> ne[1];
    newam[0] = ne[0][0] - 48;
    newam[1] = ne[0][1] - 48;
    newam[2] = ne[1][1] - 48;
    newam[3] = ne[1][0] - 48;
    flag = false;
    for (int j = 0; (j < index) && (!flag); j++)
      if (aresame(am[j], newam)) flag = true;
    if (flag == false) {
      for (int j = 0; j < 4; j++) am[index][j] = newam[j];
      index++;
    }
  }
  cout << index << endl;
  return 0;
}
