#include <bits/stdc++.h>
using namespace std;
set<string> f;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    string s = "";
    while (1) {
      char c;
      cin >> c;
      if (isdigit(c)) s += c;
      if (((int)(s).size()) == 4) break;
    }
    swap(s[2], s[3]);
    string t = s;
    for (int i = 0; i < 4; ++i) {
      char c = s[0];
      for (int j = 0; j < 3; ++j) s[j] = s[j + 1];
      s[3] = c;
      if (s < t) t = s;
    }
    if (!f.count(t)) ++ans;
    f.insert(t);
  }
  cout << ans << endl;
  return 0;
}
