#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000 + 10;
int a[MAX_N][4], n, ans;
bool check[6][6][6][6];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    char x, y, z, t;
    cin >> x >> y >> z >> t;
    a[i][0] = x - '1';
    a[i][1] = y - '1';
    a[i][3] = z - '1';
    a[i][2] = t - '1';
    if (i < n - 1) cin >> x >> y;
    int p = 0, tt = 0;
    while (p < 6) {
      int tg = a[i][0];
      for (int j = 0; j < 3; j++) a[i][j] = a[i][j + 1];
      a[i][3] = tg;
      p++;
      if (check[a[i][0]][a[i][1]][a[i][2]][a[i][3]]) {
        tt++;
      }
      check[a[i][0]][a[i][1]][a[i][2]][a[i][3]] = true;
    }
    if (tt < p) ans++;
  }
  cout << ans << endl;
  return 0;
}
