#include <bits/stdc++.h>
using namespace std;
int dirty[3001];
vector<string> groups;
int main() {
  int n;
  cin >> n;
  while (n--) {
    string r1, r2;
    cin >> r1 >> r2;
    bool contains = false;
    for (std::vector<int>::size_type i = 0; i != groups.size(); i++) {
      char etalon1 = groups[i][0];
      char etalon2 = groups[i][1];
      char etalon3 = groups[i][2];
      char etalon4 = groups[i][3];
      char r11 = r1[0];
      char r12 = r1[1];
      char r21 = r2[0];
      char r22 = r2[1];
      if ((etalon1 == r11 && etalon2 == r12 && etalon3 == r21 &&
           etalon4 == r22) ||
          (etalon1 == r21 && etalon2 == r11 && etalon3 == r22 &&
           etalon4 == r12) ||
          (etalon1 == r22 && etalon2 == r21 && etalon3 == r12 &&
           etalon4 == r11) ||
          (etalon1 == r12 && etalon2 == r22 && etalon3 == r11 &&
           etalon4 == r21)) {
        contains = true;
        break;
      }
    }
    if (contains == false) groups.insert(groups.begin(), r1 + r2);
    if (n > 0) {
      string s;
      cin >> s;
    }
  }
  cout << groups.size();
  return 0;
}
