#include <bits/stdc++.h>
using namespace std;
const int SIZE = 10000;
int R[SIZE];
int main() {
  int N, a, b, c, d, r, k;
  char ch;
  cin >> N;
  while (N--) {
    r = SIZE;
    cin >> ch;
    a = ch - '0';
    cin >> ch;
    b = ch - '0';
    cin >> ch;
    d = ch - '0';
    cin >> ch;
    c = ch - '0';
    k = 1000 * a + 100 * b + 10 * c + d;
    if (r > k) r = k;
    k = 1000 * b + 100 * c + 10 * d + a;
    if (r > k) r = k;
    k = 1000 * c + 100 * d + 10 * a + b;
    if (r > k) r = k;
    k = 1000 * d + 100 * a + 10 * b + c;
    if (r > k) r = k;
    R[r]++;
    cin >> ch >> ch;
  }
  int res = 0;
  for (int i = 0; i != SIZE; i++)
    if (R[i]) res++;
  cout << res;
  return 0;
}
