#include <bits/stdc++.h>
using namespace std;
bool same(int a, int b, int c, int d, int e, int f, int g, int h) {
  if (a == e && b == f && c == g && d == h) return 1;
  if (a == f && b == h && c == e && d == g) return 1;
  if (a == h && b == g && c == f && d == e) return 1;
  if (a == g && b == e && c == h && d == f) return 1;
  return 0;
}
int main() {
  int a[1001], b[1001], c[1001], d[1001], t = 0, x, y;
  int n, i, j;
  string s;
  bool f[1001] = {};
  cin >> n;
  for (i = 1; i < n; i++) {
    cin >> x >> y >> s;
    a[i] = x / 10;
    b[i] = x % 10;
    c[i] = y / 10;
    d[i] = y % 10;
  }
  cin >> x >> y;
  a[n] = x / 10;
  b[n] = x % 10;
  c[n] = y / 10;
  d[n] = y % 10;
  for (i = 1; i < n; i++) {
    for (j = i + 1; j <= n; j++)
      if (same(a[i], b[i], c[i], d[i], a[j], b[j], c[j], d[j])) f[j] = 1;
  }
  for (i = 1; i <= n; i++)
    if (!f[i]) t++;
  cout << t;
  return 0;
}
