#include <bits/stdc++.h>
using namespace std;
const int mx = (int)2e5 + 6;
string s1, s2, s;
set<string> Set;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    if (i) {
      cin >> s;
    }
    cin >> s1 >> s2;
    reverse(s2.begin(), s2.end());
    s1 += s2;
    string mn = s1;
    for (int j = 1; j <= 4; ++j) {
      mn = min(mn, s1);
      swap(s1[0], s1[1]);
      swap(s1[0], s1[2]);
      swap(s1[0], s1[3]);
    }
    Set.insert(mn);
  }
  cout << Set.size() << endl;
  return 0;
}
