#include <bits/stdc++.h>
using namespace std;
int ToInt(string& s, int len) {
  int r = 0;
  for (int i = 0, max_ = (len); i < max_; ++i) {
    r *= 10;
    r += s[i] - '0';
  }
  return r;
}
int GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; }
int LCM(int a, int b) { return a * (b / GCD(a, b)); }
long long Pow(long long n, long long e) {
  if (e == 0) return 1;
  if (e == 1)
    return n;
  else if (e & 1) {
    long long t = Pow(n, e / 2);
    return n * t * t;
  } else {
    long long t = Pow(n, e / 2);
    return t * t;
  }
}
char v[1001][4];
bool ok[1001];
bool Same(int i, int j) {
  if (v[i][0] == v[j][0] && v[i][1] == v[j][1] && v[i][2] == v[j][2] &&
      v[i][3] == v[j][3])
    return true;
  if (v[i][0] == v[j][1] && v[i][1] == v[j][3] && v[i][2] == v[j][0] &&
      v[i][3] == v[j][2])
    return true;
  if (v[i][0] == v[j][3] && v[i][1] == v[j][2] && v[i][2] == v[j][1] &&
      v[i][3] == v[j][0])
    return true;
  if (v[i][0] == v[j][2] && v[i][1] == v[j][0] && v[i][2] == v[j][3] &&
      v[i][3] == v[j][1])
    return true;
  return false;
}
int main() {
  char c;
  int N;
  scanf("%d", &N);
  for (int i = 0, max_ = (N); i < max_; ++i) {
    for (int j = 0, max_ = (4); j < max_; ++j) cin >> v[i][j];
    cin >> c >> c;
  }
  memset(ok, true, sizeof(ok));
  ;
  for (int i = 0, max_ = (N); i < max_; ++i) {
    if (!ok[i]) continue;
    for (int j = (i + 1), max_ = (N); j < max_; ++j)
      if (Same(i, j)) ok[j] = false;
  }
  int res = 0;
  for (int i = 0, max_ = (N); i < max_; ++i)
    if (ok[i]) ++res;
  printf("%d\n", res);
  return 0;
}
