#include <bits/stdc++.h>
using namespace std;
struct amulet {
  int a[4];
};
bool operator==(amulet a, amulet b) {
  int i, j;
  for (j = 0; j < 4; ++j) {
    for (i = 0; i < 4; ++i) {
      if (a.a[i] != b.a[(i + j) % 4]) break;
    }
    if (i == 4) return true;
  }
  return false;
}
const int MAXN = 1100;
amulet am[MAXN];
bool used[MAXN];
int main() {
  int n;
  char c;
  int i, j;
  cin >> n;
  for (i = 0; i < n - 1; ++i) {
    for (j = 0; j < 4; ++j) {
      cin >> c;
      am[i].a[j] = c - '0';
    }
    swap(am[i].a[3], am[i].a[2]);
    cin >> c >> c;
  }
  for (j = 0; j < 4; ++j) {
    cin >> c;
    am[i].a[j] = c - '0';
  }
  swap(am[i].a[3], am[i].a[2]);
  memset(used, 0, sizeof(used));
  int ans = 0;
  for (i = 0; i < n; ++i)
    if (!used[i]) {
      ++ans;
      used[i] = true;
      for (j = i + 1; j < n; ++j)
        if (am[i] == am[j]) {
          used[j] = true;
        }
    }
  cout << ans << endl;
  return 0;
}
