#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T power(T x, T p) {
  if (!p) return 1;
  return x * power(x, p - 1);
}
const int mx = 0;
int main() {
  int n;
  while (cin >> n) {
    string tt;
    set<string> ans;
    for (__typeof(n) i = 0; i < (n); i++) {
      if (i) cin >> tt;
      string a, b;
      cin >> a >> b;
      vector<string> num;
      tt = "";
      tt += a[0];
      tt += a[1];
      tt += b[1];
      tt += b[0];
      num.push_back(tt);
      tt = "";
      tt += a[1];
      tt += b[1];
      tt += b[0];
      tt += a[0];
      num.push_back(tt);
      tt = "";
      tt += b[1];
      tt += b[0];
      tt += a[0];
      tt += a[1];
      num.push_back(tt);
      tt = "";
      tt += b[0];
      tt += a[0];
      tt += a[1];
      tt += b[1];
      num.push_back(tt);
      sort(num.begin(), num.end());
      ans.insert(num[0]);
    }
    cout << int(ans.size()) << endl;
  }
  return 0;
}
