#include <bits/stdc++.h>
using namespace std;
int solve() {
  int n;
  cin >> n;
  set<int> s[1000];
  for (int i = 0; i < n; i++) {
    string f, l, ss;
    cin >> f >> l;
    reverse(l.begin(), l.end());
    ss = f + l;
    s[i].insert(atoi(ss.c_str()));
    for (int j = 0; j < 3; j++) {
      rotate(ss.begin(), ss.begin() + 1, ss.end());
      s[i].insert(atoi(ss.c_str()));
    }
    if (i != n - 1) cin >> f;
  }
  bool fl[1000];
  for (int i = 0; i < n; i++) fl[i] = false;
  set<int> ss;
  ss.insert(0);
  for (int i = 1; i < n; i++) {
    set<int>::iterator ii = ss.begin(), jj;
    bool flag = false;
    while (ii != ss.end()) {
      jj = s[i].begin();
      while (jj != s[i].end()) {
        if (binary_search(s[*ii].begin(), s[*ii].end(), *jj)) {
          flag = true;
        }
        jj++;
      }
      ii++;
    }
    if (!flag) {
      ss.insert(i);
    }
  }
  return ss.size();
}
int main(int argc, char *argv[]) {
  cout << solve() << endl;
  return 0;
}
