#include <bits/stdc++.h>
using namespace std;
void solve() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  int arr[4];
  set<string> all;
  int trip = 0;
  string a, b, bl;
  for (int i = 0; i < n - 1; ++i) {
    trip = 0;
    cin >> a >> b >> bl;
    reverse(b.begin(), b.end());
    a = a + b;
    for (int j = 0; j < 4 && trip == 0; ++j) {
      string S = "";
      for (int k = j; k < j + 4; ++k) {
        S += a[(k % 4)];
      }
      if (all.find(S) != all.end()) {
        trip = 1;
        break;
      }
    }
    if (!trip) {
      all.insert(a);
    }
  }
  trip = 0;
  cin >> a >> b;
  reverse(b.begin(), b.end());
  a = a + b;
  for (int j = 0; j < 4 && trip == 0; ++j) {
    string S = "";
    for (int k = j; k < j + 4; ++k) {
      S += a[(k % 4)];
    }
    if (all.find(S) != all.end()) {
      trip = 1;
      break;
    }
  }
  if (!trip) {
    all.insert(a);
  }
  cout << all.size() << "\n";
  return 0;
}
