#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unsigned short int** ar = new unsigned short int*[n];
  bool* checked = new bool[n];
  unsigned short int pair_1;
  unsigned short int pair_2;
  string trash;
  int n_piles = 0;
  for (int i = 0; i < n; i++) {
    checked[i] = false;
    cin >> pair_1;
    cin >> pair_2;
    ar[i] = new unsigned short int[4];
    ar[i][0] = pair_1 / 10;
    ar[i][1] = pair_1 % 10;
    ar[i][2] = pair_2 / 10;
    ar[i][3] = pair_2 % 10;
    if (i == n - 1) {
    } else {
      cin >> trash;
    }
  }
  for (int i = 0; i < n; i++) {
    if (checked[i]) {
      continue;
    }
    checked[i] = true;
    n_piles++;
    for (int j = 0; j < n; j++) {
      if (checked[j]) {
        continue;
      }
      unsigned short int h[4] = {0, 1, 2, 3};
      for (int k = 0; k < 4; k++) {
        if ((ar[i][0] == ar[j][h[0]]) && (ar[i][1] == ar[j][h[1]]) &&
            (ar[i][2] == ar[j][h[2]]) && (ar[i][3] == ar[j][h[3]])) {
          checked[j] = true;
        }
        if (k == 0) {
          h[0] = 1;
          h[1] = 3;
          h[2] = 0;
          h[3] = 2;
        } else if (k == 1) {
          h[0] = 3;
          h[1] = 2;
          h[2] = 1;
          h[3] = 0;
        } else if (k == 2) {
          h[0] = 2;
          h[1] = 0;
          h[2] = 3;
          h[3] = 1;
        } else {
        };
      }
    }
  }
  cout << n_piles;
  return 0;
}
