#include <bits/stdc++.h>
using namespace std;
const int mm = 1700;
char s[mm][77];
char t[77], tt[77];
int main() {
  int n, pos;
  while (cin >> n) {
    pos = 0;
    for (int i = 0; i < n; i++) {
      cin >> t >> tt;
      t[2] = tt[1];
      t[3] = tt[0];
      for (int j = 0; j < 4; j++) t[j + 4] = t[j];
      t[8] = '\0';
      bool flag = 0;
      for (int j = 0; j < pos && !flag; j++) {
        for (int k = 0; k < 4 && !flag; k++) {
          int kk = k, z = 0;
          for (; kk < k + 4;)
            if (t[kk] == s[j][z])
              z++, kk++;
            else
              break;
          if (z == 4) flag = 1;
        }
      }
      if (!flag) {
        strcpy(s[pos], t);
        pos++;
      }
      if (i != n - 1) cin >> tt;
    }
    cout << pos << "\n";
  }
}
