#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  cin >> n;
  string s = "";
  set<string> in;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a;
    cin >> b;
    if (i != n - 1) {
      string aa;
      cin >> aa;
    }
    a += b[1];
    a += b[0];
    if (in.find(a) == in.end()) {
      ans++;
    }
    for (int j = 0; j < 4; j++) {
      in.insert(a);
      char tmp = a[0];
      a[0] = a[1];
      a[1] = a[2];
      a[2] = a[3];
      a[3] = tmp;
    }
  }
  cout << ans << endl;
}
