#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> strs;
  int n = 0;
  int j = 0;
  int count = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    if (i != 0) {
      string temp = "";
      cin >> temp;
    }
    string str1 = "";
    string str2 = "";
    string str3 = "";
    string str4 = "";
    string str5 = "";
    string str6 = "";
    cin >> str1 >> str2;
    str3 += str1.at(0);
    str3 += str1.at(1);
    str3 += str2.at(0);
    str3 += str2.at(1);
    str3 += str3;
    str4 += str2.at(0);
    str4 += str1.at(0);
    str4 += str2.at(1);
    str4 += str1.at(1);
    str4 += str4;
    str5 += str2.at(1);
    str5 += str2.at(0);
    str5 += str1.at(1);
    str5 += str1.at(0);
    str5 += str5;
    str6 += str1.at(1);
    str6 += str2.at(1);
    str6 += str1.at(0);
    str6 += str2.at(0);
    str6 += str6;
    if (i == 0) {
      strs.push_back(str3);
      strs.push_back(str4);
      strs.push_back(str5);
      strs.push_back(str6);
      count++;
    } else {
      bool check = false;
      for (int j = 0; j < strs.size(); j++) {
        if (!strs[j].find(str1 + str2)) {
          check = true;
          break;
        }
      }
      if (!check) {
        strs.push_back(str3);
        strs.push_back(str4);
        strs.push_back(str5);
        strs.push_back(str6);
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}
