#include <bits/stdc++.h>
using namespace std;
int n;
char a[1000][4];
char z1, z2;
int g, f;
void per(int p) {
  char b[4][4];
  b[0][0] = a[p][0];
  b[0][1] = a[p][1];
  b[0][2] = a[p][2];
  b[0][3] = a[p][3];
  b[1][0] = a[p][2];
  b[1][1] = a[p][0];
  b[1][2] = a[p][3];
  b[1][3] = a[p][1];
  b[2][0] = a[p][3];
  b[2][1] = a[p][2];
  b[2][2] = a[p][1];
  b[2][3] = a[p][0];
  b[3][0] = a[p][1];
  b[3][1] = a[p][3];
  b[3][2] = a[p][0];
  b[3][3] = a[p][2];
  for (int i = 0; i < 3; i++)
    for (int j = i + 1; j < 4; j++) {
      if (b[i][0] > b[j][0] ||
          b[i][0] == b[j][0] &&
              (b[i][1] > b[j][1] ||
               b[i][1] == b[j][1] && (b[i][2] > b[j][2] ||
                                      b[i][2] == b[j][2] && b[i][3] > b[j][3])))
        for (int k = 0; k < 4; k++) swap(b[i][k], b[j][k]);
    }
  for (int i = 0; i < 4; i++) a[p][i] = b[0][i];
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    if (i != 0) cin >> z1 >> z2;
    for (int j = 0; j < 4; j++) cin >> a[i][j];
  }
  for (int i = 0; i < n; i++) per(i);
  g = 1;
  for (int i = 1; i < n; i++) {
    f = 0;
    for (int j = 0; j < i && f == 0; j++)
      if (a[i][0] == a[j][0] && a[i][1] == a[j][1] && a[i][2] == a[j][2] &&
          a[i][3] == a[j][3])
        f = 1;
    if (f == 0) g++;
  }
  cout << g;
  return 0;
}
