#include <bits/stdc++.h>
using namespace std;
set<string> S;
int main() {
  int n;
  string s;
  string s1, s2;
  while (cin >> n) {
    S.clear();
    int T = 0;
    int res = 0;
    for (int i = 0; i < n; i++) {
      cin >> s1 >> s2;
      if (i != n - 1) cin >> s;
      s1 += s2[1];
      s1 += s2[0];
      bool have = false;
      for (int j = 0; j < 4; j++) {
        string tem = "";
        for (int k = j, ct = 0; ct < 4; ct++, k++) {
          tem += s1[k % 4];
        }
        if (S.find(tem) == S.end()) {
          have = true;
          S.insert(tem);
        }
      }
      if (have) res++;
    }
    cout << res << endl;
  }
  return 0;
}
