#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string star;
  string b;
  map<string, bool> used;
  char ch;
  int ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    b = "";
    for (int g = 0; g < 4; g++) {
      cin >> ch;
      b += ch;
    }
    b = b.substr(0, 2) + b[3] + b[2];
    if (!used[b] && !used[b.substr(1, b.length()) + b[0]] &&
        !used[b.substr(2, b.length()) + b[0] + b[1]] &&
        !used[b.substr(3, b.length()) + b[0] + b[1] + b[2]]) {
      ans++;
      used[b] = true;
      used[b.substr(1, b.length()) + b[0]] = true;
      used[b.substr(2, b.length()) + b[0] + b[1]] = true;
      used[b.substr(3, b.length()) + b[0] + b[1] + b[2]] = true;
    }
    if (i < n - 1) cin >> star;
  }
  cout << ans << endl;
}
