#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
int main() {
  int N;
  cin >> N;
  set<string> piles;
  for (int n = 0; n < (int)N; ++n) {
    string a, b, dummy;
    cin >> a >> b >> dummy;
    a += b[1];
    a += b[0];
    string best = a;
    for (int i = 0; i < (int)4; ++i) {
      rotate(a.begin(), a.begin() + 1, a.end());
      best = min(best, a);
    }
    piles.insert(best);
  }
  cout << piles.size() << endl;
}
