#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; i++) {
    string s, w;
    cin >> s >> w;
    reverse(w.begin(), w.end());
    string val = s + "" + w;
    val = val + "" + val;
    int flag = 0;
    for (int j = 0; j < 4; j++) {
      if (mp.count(val.substr(j, 4))) {
        flag = 1;
      }
    }
    if (!flag) {
      mp[val.substr(0, 4)] = 1;
    }
    if (i != n - 1) {
      cin >> s;
    }
  }
  cout << mp.size() << "\n";
}
