#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
string dec(string s) {
  s += s;
  string res = s.substr(0, 4);
  for (int i = 0; i < (4); ++i)
    res = (res > (s.substr(i, 4))) ? (s.substr(i, 4)) : res;
  return res;
}
int main() {
  int n;
  string acc, t;
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    acc = "";
    for (int j = 0; j < (2); ++j) {
      cin >> t;
      if (j) reverse((t).begin(), (t).end());
      acc += t;
    }
    cin >> t;
    m[dec(acc)]++;
  }
  cout << (int)(m).size() << endl;
  return 0;
}
