#include <bits/stdc++.h>
using namespace std;
string S;
struct Dom {
  vector<int> Val;
  Dom() {}
  void load() {
    Val.clear();
    int A;
    cin >> A;
    Val.push_back(A / 10);
    Val.push_back(A % 10);
    cin >> A;
    Val.push_back(A % 10);
    Val.push_back(A / 10);
    cin >> S;
  }
  bool operator==(Dom D) {
    bool IsSame = true;
    for (int d = 0; d < 4; ++d) {
      IsSame = true;
      for (int i = 0; i < 4; ++i) IsSame &= (Val[(i + d) % 4] == D.Val[i]);
      if (IsSame) return true;
    }
    return false;
  }
};
int main() {
  vector<Dom> Domin;
  int N;
  cin >> N;
  Domin.resize(N);
  for (int i = 0; i < N; ++i) Domin[i].load();
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    bool IsUnical = true;
    for (int j = i + 1; j < N; ++j)
      if (Domin[i] == Domin[j]) IsUnical = false;
    if (IsUnical) ++cnt;
  }
  cout << cnt;
  return 0;
}
