#include <bits/stdc++.h>
using namespace std;
const double EPS = 1E-10;
void dbg(vector<int> a) {
  for (size_t i = 0; i < a.size(); i++) {
    printf("%d ", a[i]);
  }
  printf("\n");
}
void dbg(vector<vector<int> > a) {
  for (size_t i = 0; i < a.size(); i++) {
    dbg(a[i]);
  }
}
void dbg(vector<string> a) {
  for (size_t i = 0; i < a.size(); i++) {
    printf("%s\n", a[i].data());
  }
}
void openf(const string &fname, string mode = "") {
  string fin = fname + ".in";
  string fout = fname + ".out";
  if (mode.size() == 1 && mode[0] == 'r') freopen(fin.data(), "r", stdin);
  if (mode.size() == 1 && mode[0] == 'w') freopen(fout.data(), "w", stdout);
  if (mode.size() == 2) {
    freopen(fin.data(), "r", stdin);
    freopen(fout.data(), "w", stdout);
  }
}
struct am {
  int a, b, c, d;
  am() { a = b = c = d = 0; }
  am(int e, int r, int t, int y) {
    a = e;
    b = r;
    c = t;
    d = y;
  }
};
am shift(am a) {
  int y = a.a;
  a.a = a.b;
  a.b = a.c;
  a.c = a.d;
  a.d = y;
  return a;
}
bool iseq(am x, am y) {
  if (x.a == y.a && x.b == y.b && x.c == y.c && x.d == y.d) return true;
  y = shift(y);
  if (x.a == y.a && x.b == y.b && x.c == y.c && x.d == y.d) return true;
  y = shift(y);
  if (x.a == y.a && x.b == y.b && x.c == y.c && x.d == y.d) return true;
  y = shift(y);
  if (x.a == y.a && x.b == y.b && x.c == y.c && x.d == y.d) return true;
  return false;
}
am m[1001];
int main() {
  memset(m, 0, sizeof(m));
  int n;
  cin >> n;
  string s;
  char a, b, c, d;
  for (int i = 0; i < n; i++) {
    am t;
    cin >> s;
    t.a = s[0] - '0';
    t.b = s[1] - '0';
    cin >> s;
    t.c = s[1] - '0';
    t.d = s[0] - '0';
    m[i] = t;
    cin >> s;
  }
  bool used[1001];
  memset(used, 0, sizeof(used));
  int k = 0;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      k++;
      used[i] = true;
      for (int j = i + 1; j < n; j++) {
        if (!used[j] && iseq(m[i], m[j])) {
          used[j] = true;
        }
      }
    }
  }
  cout << k;
  return 0;
}
