#include <bits/stdc++.h>
using namespace std;
struct Amulet {
  char p[2][2];
  void Read() { cin >> p[0][0] >> p[0][1] >> p[1][0] >> p[1][1]; }
  Amulet Rotate() const {
    Amulet ret(*this);
    ret.p[0][0] = this->p[0][1];
    ret.p[0][1] = this->p[1][1];
    ret.p[1][0] = this->p[0][0];
    ret.p[1][1] = this->p[1][0];
    return ret;
  }
};
bool Equiv(Amulet const& a1, Amulet const& a2) {
  return a1.p[0][0] == a2.p[0][0] && a1.p[0][1] == a2.p[0][1] &&
         a1.p[1][0] == a2.p[1][0] && a1.p[1][1] == a2.p[1][1];
}
bool operator==(Amulet const& a1, Amulet const& a2) {
  Amulet tmp(a1);
  for (int i = 0; i < 4; ++i) {
    if (Equiv(tmp, a2)) return true;
    tmp = tmp.Rotate();
  }
  return false;
}
int main() {
  vector<Amulet> v;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    Amulet a;
    a.Read();
    vector<Amulet>::iterator it = find(v.begin(), v.end(), a);
    if (it == v.end()) {
      v.push_back(a);
    }
    char dummy;
    cin >> dummy >> dummy;
  }
  cout << v.size() << endl;
}
