#include <bits/stdc++.h>
using namespace std;
vector<string> bag;
vector<string> source[4];
int n;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s, s1;
    cin >> s >> s1;
    if (i < n - 1) {
      string t;
      cin >> t;
    }
    reverse(s1.begin(), s1.end());
    s += s1;
    for (int j = 0; j < 4; ++j) {
      source[j].push_back(s.substr(j, 4 - j) + s.substr(0, j));
    }
  }
  for (int i = 0; i < n; ++i) {
    bool find = false;
    for (int j = 0; j < bag.size() && !find; ++j) {
      for (int k = 0; k < 4 && !find; ++k) {
        if (bag[j] == source[k][i]) {
          find = true;
        }
      }
    }
    if (!find) {
      bag.push_back(source[0][i]);
    }
  }
  cout << bag.size() << endl;
  return 0;
}
