#include <bits/stdc++.h>
using namespace std;
const long double epsylon = 1e-9;
int b[4];
int main() {
  string t, u;
  int n;
  cin >> n;
  getline(cin, t);
  set<int> a;
  for (int i = 0; i < n; i++) {
    getline(cin, t);
    getline(cin, u);
    b[0] = t[0] - '0';
    b[1] = t[1] - '0';
    b[2] = u[1] - '0';
    b[3] = u[0] - '0';
    int bi = 0;
    int bc = b[0] * 1000 + b[1] * 100 + b[2] * 10 + b[3];
    for (int l = 1; l < 4; l++) {
      int tc = b[l] * 1000 + b[(l + 1) % 4] * 100 + b[(l + 2) % 4] * 10 +
               b[(l + 3) % 4];
      if (tc < bc) {
        bc = tc;
      }
    }
    a.insert(bc);
    getline(cin, t);
  }
  cout << a.size() << endl;
  return 0;
}
