#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;
  int a, b, c, d;
  a = s1[0] - '0';
  b = s1[1] - '0';
  c = s2[1] - '0';
  d = s2[0] - '0';
  vector<int> v1({a, b, c, d});
  map<vector<int>, int> mp;
  mp[{a, b, c, d}] = 1;
  n--;
  while (n--) {
    string s;
    cin >> s;
    cin >> s1 >> s2;
    a = s1[0] - '0';
    b = s1[1] - '0';
    c = s2[1] - '0';
    d = s2[0] - '0';
    vector<int> v1({a, b, c, d});
    vector<int> v2({b, c, d, a});
    vector<int> v3({c, d, a, b});
    vector<int> v4({d, a, b, c});
    if (mp.find({a, b, c, d}) != mp.end()) {
      continue;
    } else if (mp.find({b, c, d, a}) != mp.end()) {
      continue;
    } else if (mp.find({c, d, a, b}) != mp.end()) {
      continue;
    } else if (mp.find({d, a, b, c}) != mp.end()) {
      continue;
    } else
      mp[{a, b, c, d}] = 1;
  }
  cout << mp.size() << endl;
  return 0;
}
