#include <bits/stdc++.h>
using namespace std;
int min_rotation(vector<char> s) {
  int a = 0, N = int(s.size());
  s.insert(s.end(), s.begin(), s.end());
  for (int b = 0; b < int(N); ++b)
    for (int i = 0; i < int(N); ++i) {
      if (a + i == b || s[a + i] < s[b + i]) {
        b += max(0, i - 1);
        break;
      }
      if (s[a + i] > s[b + i]) {
        a = b;
        break;
      }
    }
  return a;
}
vector<char> rot_min(vector<char> v) {
  int x = min_rotation(v);
  rotate(v.begin(), v.begin() + x, v.end());
  return v;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  vector<vector<char> > all;
  while (t--) {
    vector<char> v(4);
    cin >> v[0] >> v[1];
    cin >> v[3] >> v[2];
    v = rot_min(v);
    all.push_back(v);
    char x;
    cin >> x >> x;
  }
  sort(all.begin(), all.end());
  all.erase(unique(all.begin(), all.end()), all.end());
  cout << int(all.size()) << '\n';
  return 0;
}
