#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic warning "-Wall"
vector<int> read() {
  vector<int> v(4);
  string s;
  cin >> s;
  v[0] = s[0] - '0';
  v[1] = s[1] - '0';
  cin >> s;
  v[2] = s[1] - '0';
  v[3] = s[0] - '0';
  cin >> s;
  vector<vector<int> > vv;
  for (typeof(4) i = (0); i < (4); i++) {
    vector<int> u(4);
    for (typeof(4) j = (0); j < (4); j++) {
      u[j] = v[(j + i) % 4];
    }
    vv.push_back(u);
  }
  sort((vv).begin(), (vv).end());
  return vv[0];
}
int main() {
  int N;
  cin >> N;
  vector<vector<int> > vv;
  for (typeof(N) i = (0); i < (N); i++) {
    vector<int> v = read();
    vv.push_back(v);
  }
  sort((vv).begin(), (vv).end());
  cout << distance(vv.begin(), unique((vv).begin(), (vv).end())) << endl;
}
