#include <bits/stdc++.h>
using namespace std;
bool pile[6667];
int main() {
  int N;
  scanf("%d\n", &N);
  int cn = 0;
  for (int i = 0; i < N; i++) {
    int a, b, c, d;
    a = getchar() - '0';
    b = getchar() - '0';
    getchar();
    c = getchar() - '0';
    d = getchar() - '0';
    getchar();
    int rep = min(min(min(a * 1000 + b * 100 + d * 10 + c,
                          b * 1000 + d * 100 + c * 10 + a),
                      c * 1000 + a * 100 + b * 10 + d),
                  d * 1000 + c * 100 + a * 10 + b);
    if (!pile[rep]) {
      pile[rep] = true;
      cn++;
    }
    if (i != N - 1) {
      getchar();
      getchar();
      getchar();
    }
  }
  printf("%d\n", cn);
}
