#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int a[4];
set<int> se;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) {
    cin >> s;
    a[0] = s[0] - '0';
    a[1] = s[1] - '0';
    cin >> s;
    a[3] = s[0] - '0';
    a[2] = s[1] - '0';
    if (i < n - 1) cin >> s;
    int mn = (int)1e9;
    for (int j = 0; j < (int)(4); ++j) {
      int cur = 0;
      for (int k = 0; k < (int)(4); ++k) cur = 11 * cur + a[k];
      mn = min(mn, cur);
      if (j < 3) {
        int tmp = a[0];
        for (int k = 0; k < (int)(3); ++k) a[k] = a[k + 1];
        a[3] = tmp;
      }
    }
    se.insert(mn);
  }
  cout << (int)se.size() << endl;
  return 0;
}
