#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  map<string, int> M;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string a, b;
    if (i > 0) {
      cin >> a;
    }
    cin >> a >> b;
    reverse(b.begin(), b.end());
    a += b;
    string s = a;
    for (int j = 0; j < 4; ++j) {
      char c = a[3];
      a.pop_back();
      a = c + a;
      if (s > a) s = a;
    }
    M[s]++;
  }
  cout << M.size() << "\n";
  return 0;
}
