#include <bits/stdc++.h>
using namespace std;
set<string> S;
void flip(string& s1) {
  char temp = s1[0];
  for (int i = 1; i < 4; i++) s1[i - 1] = s1[i];
  s1[3] = temp;
  return;
}
bool isFirst(string s1) {
  for (int i = 0; i < 4; i++) {
    if (S.find(s1) != S.end()) return false;
    flip(s1);
  }
  return true;
}
int main() {
  int N, result(0);
  string s1, s2;
  cin >> N;
  cin >> s1 >> s2;
  s1 += s2[1];
  s1 += s2[0];
  if (isFirst(s1)) {
    S.insert(s1);
    result++;
  }
  for (int i = 1; i < N; i++) {
    cin >> s1;
    cin >> s1 >> s2;
    s1 += s2[1];
    s1 += s2[0];
    if (isFirst(s1)) {
      S.insert(s1);
      result++;
    }
  }
  cout << result << endl;
}
