#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
long long gcd(long long m, long long n) { return n ? gcd(n, m % n) : m; }
long long pail(long long m) {
  long long sum = 0;
  long long n = m;
  while (m) {
    sum = sum * 10 + m % 10;
    m /= 10;
  }
  if (n == sum)
    return 1;
  else
    return 0;
}
long long prime(long long n) {
  int f = 0;
  for (long long i = 2; i <= sqrt(n * 1.0); ++i) {
    if (n % i == 0) {
      f = 1;
      return 1;
    }
  }
  if (n == 1 || n == 2) return 0;
  if (f == 0) return 0;
}
void quick_sort(int q[], int l, int r) {
  if (l >= r) return;
  int i = l - 1, j = r + 1, x = q[l + r >> 1];
  while (i < j) {
    do i++;
    while (q[i] < x);
    do j--;
    while (q[j] > x);
    if (i < j) swap(q[i], q[j]);
  }
  quick_sort(q, l, j);
  quick_sort(q, j + 1, r);
}
bool cmp(int a, int b) { return a > b; }
int sum(int a, int b, int c, int d) {
  int s = a * 1000 + b * 100 + c * 10 + d;
  return s;
}
int main() {
  int n;
  cin >> n;
  char ch[3] = "**";
  int a, b;
  cin >> a >> b;
  int s[4000] = {0};
  s[0] = sum(a / 10, a % 10, b % 10, b / 10);
  s[1] = sum(a % 10, b % 10, b / 10, a / 10);
  s[2] = sum(b % 10, b / 10, a / 10, a % 10);
  s[3] = sum(b / 10, a / 10, a % 10, b % 10);
  int cnt = 4;
  int ans = 1;
  for (int i = 0; i < n - 1; ++i) {
    cin >> ch;
    int c;
    int d;
    cin >> c >> d;
    int f = 0;
    for (int j = 0; j < cnt; ++j) {
      if (sum(c / 10, c % 10, d % 10, d / 10) == s[j]) {
        f = 1;
        break;
      }
    }
    if (f == 0) {
      ans++;
      s[cnt++] = sum(c / 10, c % 10, d % 10, d / 10);
      s[cnt++] = sum(c % 10, d % 10, d / 10, c / 10);
      s[cnt++] = sum(d % 10, d / 10, c / 10, c % 10);
      s[cnt++] = sum(d / 10, c / 10, c % 10, d % 10);
    }
  }
  cout << ans << endl;
  return 0;
}
