#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.1415926535897932384626433832795029L;
string f(string A) {
  string B = A;
  B[0] = A[1];
  B[1] = A[3];
  B[2] = A[0];
  B[3] = A[2];
  return B;
}
bool solve(int testNumber) {
  int n;
  if (scanf("%d", &n) == EOF) return false;
  set<string> S;
  while (n--) {
    string str, aux;
    cin >> str >> aux;
    str += aux;
    if (n) cin >> aux;
    string mini = str;
    for (int i = 0; i < 3; i++) {
      str = f(str);
      mini = min(mini, str);
    }
    S.insert(mini);
  }
  printf("%d\n", (int)S.size());
  return true;
}
int main() {
  for (int i = 1; solve(i); i++)
    ;
  return 0;
}
