#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int k = 7;
  int c = 0;
  string s;
  int a[1001][4];
  int b[1001][2];
  int x[1001][4];
  int y[1001][4];
  int z[1001][4];
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) cin >> b[i][j];
    a[i][1] = b[i][0] % 10;
    a[i][0] = b[i][0] / 10;
    a[i][2] = b[i][1] % 10;
    a[i][3] = b[i][1] / 10;
    if (i < (n - 1)) cin >> s;
  }
  for (int i = 0; i < n; i++) {
    if (a[i][0] > 6) continue;
    x[i][1] = y[i][2] = z[i][3] = a[i][0];
    x[i][2] = y[i][3] = z[i][0] = a[i][1];
    x[i][3] = y[i][0] = z[i][1] = a[i][2];
    x[i][0] = y[i][1] = z[i][2] = a[i][3];
    for (int j = i + 1; j < n; 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]) ||
          (x[i][0] == a[j][0] && x[i][1] == a[j][1] && x[i][2] == a[j][2] &&
           x[i][3] == a[j][3]) ||
          (y[i][0] == a[j][0] && y[i][1] == a[j][1] && y[i][2] == a[j][2] &&
           y[i][3] == a[j][3]) ||
          (z[i][0] == a[j][0] && z[i][1] == a[j][1] && z[i][2] == a[j][2] &&
           z[i][3] == a[j][3])) {
        a[j][0] = a[j][1] = a[j][2] = a[j][3] = k;
        k++;
      }
    c++;
  }
  cout << c;
}
