#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll OO = 1e18;
int di[8] = {0, 0, 1, -1, -1, 1, -1, 1};
int dj[8] = {1, -1, 0, 0, 1, 1, -1, -1};
string ys = "YES", no = "NO";
const long double dgr = acos(-1) / 180, dg = 180 / acos(-1);
const int mod = 1e18, N = 2e5;
char arr[1010][5];
char pile[5];
bool comp(char a[5], char b[5]) {
  for (int t = 0; t < 4; t++) {
    bool z = 1;
    for (int j = 0; j < 4; j++) {
      if (a[j] != b[j]) z = 0;
    }
    if (z) return 1;
    char i = a[0], j = a[1], x = a[2], y = a[3];
    a[0] = x;
    a[1] = i;
    a[2] = y;
    a[3] = j;
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, sz = 0;
  char q;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 4; j++) cin >> pile[j];
    bool ne = 1;
    for (int j = 0; j < sz; j++) {
      if (comp(pile, arr[j])) ne = 0;
    }
    if (ne) {
      for (int i = 0; i < 4; i++) arr[sz][i] = pile[i];
      sz++;
    }
    if (i != n) cin >> q >> q;
  }
  cout << sz << '\n';
}
