#include <bits/stdc++.h>
using namespace std;
int main() {
  bool flag = true;
  string s;
  int n, i, j, count = 0, t, k, temp;
  cin >> n;
  int arr[n][4];
  int index[n];
  for (i = 0; i < n; i++) {
    t = 0;
    for (j = 0; j < 2; j++) {
      cin >> temp;
      if (j == 0) {
        arr[i][t] = temp / 10;
        t++;
        arr[i][t] = temp % 10;
        t++;
      } else {
        arr[i][t] = temp % 10;
        t++;
        arr[i][t] = temp / 10;
        t++;
      }
    }
    if (i < n - 1) cin >> s;
  }
  index[0] = 0;
  for (i = 1; i < n; i++) {
    for (j = 0; j <= count; j++) {
      t = 0;
      while (t <= 3) {
        if (arr[i][(t) % 4] == arr[index[j]][0] &&
            arr[i][(t + 1) % 4] == arr[index[j]][1] &&
            arr[i][(t + 2) % 4] == arr[index[j]][2] &&
            arr[i][(t + 3) % 4] == arr[index[j]][3]) {
          flag = false;
          break;
        }
        t++;
      }
      if (!flag) break;
    }
    if (flag) {
      count++;
      index[count] = i;
    } else
      flag = true;
  }
  cout << count + 1 << endl;
  return 0;
}
