#include <bits/stdc++.h>
using namespace std;
struct Amulet {
  int Ele[4];
};
bool isEqual(Amulet A, Amulet B) {
  for (int i = 0; i < 4; i++) {
    if (A.Ele[0] == B.Ele[i]) {
      if (A.Ele[1] == B.Ele[(i + 1) % 4]) {
        if (A.Ele[2] == B.Ele[(i + 2) % 4]) {
          if (A.Ele[3] == B.Ele[(i + 3) % 4]) {
            return true;
          }
        }
      }
    }
  }
  return false;
}
bool checkAInV(vector<Amulet> &V, Amulet A) {
  for (int i = 0; i < V.size(); i++) {
    if (isEqual(A, V[i])) {
      return false;
    }
  }
  V.push_back(A);
  return true;
}
int main() {
  vector<Amulet> V;
  int n;
  cin >> n;
  int tmp1, tmp2;
  string S;
  Amulet A;
  for (int i = 1; i < n; i++) {
    cin >> tmp1 >> tmp2;
    cin >> S;
    A.Ele[0] = tmp1 / 10;
    A.Ele[1] = tmp1 % 10;
    A.Ele[2] = tmp2 % 10;
    A.Ele[3] = tmp2 / 10;
    checkAInV(V, A);
  }
  cin >> tmp1 >> tmp2;
  A.Ele[0] = tmp1 / 10;
  A.Ele[1] = tmp1 % 10;
  A.Ele[2] = tmp2 % 10;
  A.Ele[3] = tmp2 / 10;
  checkAInV(V, A);
  cout << V.size();
}
