#include <bits/stdc++.h>
using namespace std;
int n, t, w, x, y, z, f[8][8][8][8];
char a, b, c, d, e;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a >> b >> c >> d;
    if (i != n) cin >> e >> e;
    w = a - '0';
    x = b - '0';
    y = c - '0';
    z = d - '0';
    if (f[w][x][y][z] == 0) {
      t++;
      f[w][x][y][z] = 1;
      f[x][z][w][y] = 1;
      f[z][y][x][w] = 1;
      f[y][w][z][x] = 1;
    }
  }
  cout << t;
  return 0;
}
