#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
int a[2000][10], p[2000];
bool u[2000];
int n, res = 0;
char s[2][2];
bool bo;
void dfs(int i, int x = -1) {
  u[i] = 1;
  if (x == p[i]) return;
  if (u[p[i]]) {
    res--;
    return;
  }
  dfs(p[i], i);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("\n%s\n%s", s[0], s[1]);
    a[i - 1][0] = a[i - 1][4] = s[0][0] - '0';
    a[i - 1][1] = a[i - 1][5] = s[0][1] - '0';
    a[i - 1][2] = a[i - 1][6] = s[1][1] - '0';
    a[i - 1][3] = a[i - 1][7] = s[1][0] - '0';
    if (i < n) scanf("\n%*c%*c");
    p[i - 1] = -1;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (i != j) {
        for (int l1 = 0; l1 < 4; l1++) {
          bo = 0;
          for (int l2 = 0; l2 < 4; l2++) {
            bo = 1;
            for (int k = 0; k < 4; k++)
              if (a[i][l1 + k] != a[j][l2 + k]) {
                bo = 0;
                break;
              }
          }
          if (bo) break;
        }
        if (bo) {
          p[i] = j;
          break;
        }
      }
  for (int i = 0; i < n; i++) cerr << p[i] << " ";
  memset(u, 0, sizeof(u));
  for (int i = 0; i < n; i++)
    if (!u[i]) res++, dfs(i);
  cout << res;
  return 0;
}
