#include <bits/stdc++.h>
using namespace std;
map<int, bool> H;
int makenum(int a, int b, int c, int d) {
  return a * 1000 + b * 100 + c * 10 + d;
}
int N;
char l1[5];
char l2[5];
int main() {
  scanf("%d", &N);
  int ct = 0;
  for (int i = 0; i < N; i++) {
    scanf("%s", &l1);
    scanf("%s", &l2);
    int n1 = l1[0] - '1';
    int n2 = l1[1] - '1';
    int n3 = l2[1] - '1';
    int n4 = l2[0] - '1';
    if (H.find(makenum(n1, n2, n3, n4)) == H.end() &&
        H.find(makenum(n2, n3, n4, n1)) == H.end() &&
        H.find(makenum(n3, n4, n1, n2)) == H.end() &&
        H.find(makenum(n4, n1, n2, n3)) == H.end()) {
      ct++;
      H[makenum(n1, n2, n3, n4)] = 1;
    }
    if (i < N - 1) scanf("%s", &l1);
  }
  printf("%d\n", ct);
}
