#include <bits/stdc++.h>
using namespace std;
string str[4];
bool cmp(string aa, string bb) { return aa < bb; }
int main() {
  int n;
  string aa;
  string bb;
  string cc;
  string dd;
  while (cin >> n) {
    map<string, int> mp;
    for (int i = 1; i <= n; i++) {
      if (i < n)
        cin >> aa >> bb >> cc;
      else
        cin >> aa >> bb;
      for (int j = 0; j < 4; j++) str[j].clear();
      str[0] += aa[0];
      str[0] += aa[1];
      str[0] += bb[1];
      str[0] += bb[0];
      str[1] += aa[1];
      str[1] += bb[1];
      str[1] += bb[0];
      str[1] += aa[0];
      str[2] += bb[1];
      str[2] += bb[0];
      str[2] += aa[0];
      str[2] += aa[1];
      str[3] += bb[0];
      str[3] += aa[0];
      str[3] += aa[1];
      str[3] += bb[1];
      sort(str, str + 4, cmp);
      dd = str[0] + ',' + str[1] + ',' + str[2] + ',' + str[3];
      mp[dd]++;
    }
    cout << mp.size() << endl;
  }
  return 0;
}
