#include <bits/stdc++.h>
using namespace std;
string _90(string s) {
  string t;
  t.resize(4);
  t[0] = s[1];
  t[1] = s[3];
  t[2] = s[0];
  t[3] = s[2];
  return t;
}
string _180(string s) {
  string t;
  t.resize(4);
  t[0] = s[3];
  t[1] = s[2];
  t[2] = s[1];
  t[3] = s[0];
  return t;
}
string _270(string s) {
  string t;
  t.resize(4);
  t[0] = s[2];
  t[1] = s[0];
  t[2] = s[3];
  t[3] = s[1];
  return t;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  map<int, vector<string>> ALL;
  int n;
  cin >> n;
  string s, all;
  int id = 1, piles = 0, count_four = 0, count_all = 0, calc = 2;
  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      cin >> s;
      all = s;
      cin >> s;
      all.append(s);
    } else {
      cin >> s;
      all = s;
      cin >> s;
      all.append(s);
      cin >> s;
    }
    if (i == 0) {
      ALL[1].push_back(all);
      ALL[1].push_back(_90(all));
      ALL[1].push_back(_180(all));
      ALL[1].push_back(_270(all));
    } else {
      id = 1;
      count_four = 0, count_all = 0;
      for (int i = 0; i < ALL.size(); i++) {
        count_four = 0;
        for (int j = 0; j < ALL[id].size(); j++) {
          if (all != ALL[id][j]) {
            count_four++;
          }
        }
        id++;
        if (count_four == 4)
          count_all++;
        else {
          break;
        }
      }
      if (count_all == ALL.size()) {
        ALL[calc].push_back(all);
        ALL[calc].push_back(_90(all));
        ALL[calc].push_back(_180(all));
        ALL[calc].push_back(_270(all));
        calc++;
      }
    }
  }
  cout << ALL.size();
  return 0;
}
