#include <bits/stdc++.h>
using namespace std;
int a[1010][5];
int fa[1010];
int b[5];
char c;
int ok(int x) {
  if (fa[x] == x) return x;
  fa[x] = ok(fa[x]);
  return fa[x];
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 4; j++) {
      cin >> c;
      a[i][j] = c - 48;
    }
    swap(a[i][3], a[i][4]);
    if (i < n)
      for (int j = 1; j < 3; j++) cin >> c;
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      for (int k = 1; k <= 4; k++) b[k] = a[i][k];
      int flag = 0;
      for (int s = 1; s <= 4; s++) {
        int cur = 1;
        for (int k = 1; k <= 4; k++)
          if (b[(s + k - 1 > 4) ? s + k - 5 : s + k - 1] != a[j][k]) cur = 0;
        if (cur) flag = 1;
      }
      if (flag) {
        int p = ok(i), q = ok(j);
        fa[p] = q;
      }
    }
  for (int i = 1; i <= n; i++) fa[i] = ok(i);
  set<int> v;
  v.clear();
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (!v.count(fa[i])) ans++, v.insert(fa[i]);
  cout << ans << endl;
  return 0;
}
