#include <bits/stdc++.h>
using namespace std;
int x, y, z;
int a, b, c, d;
int a1, a2, a3, a4;
int t, s, m, n;
int Per[100555];
int ANS, ans;
char S[100];
int AA[9][9][9][9];
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  a1 = m / 10;
  a2 = m % 10;
  scanf("%d", &m);
  a3 = m % 10;
  a4 = m / 10;
  AA[a1][a2][a3][a4] = 1;
  AA[a2][a3][a4][a1] = 1;
  AA[a3][a4][a1][a2] = 1;
  AA[a4][a1][a2][a3] = 1;
  ans++;
  for (int i = 0; i < n - 1; i++) {
    scanf("%s", &S);
    scanf("%d", &m);
    a1 = m / 10;
    a2 = m % 10;
    scanf("%d", &m);
    a3 = m % 10;
    a4 = m / 10;
    if (AA[a1][a2][a3][a4] == 0) {
      AA[a1][a2][a3][a4] = 1;
      AA[a2][a3][a4][a1] = 1;
      AA[a3][a4][a1][a2] = 1;
      AA[a4][a1][a2][a3] = 1;
      ans++;
    }
  }
  printf("%d\n", ans);
}
