#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  int n = 0;
  scanf("%i", &n);
  int count = 0;
  std::vector<string> cc;
  for (int i = 0; i < n; i++) {
    static char d[3];
    static string c = "0000";
    scanf("%s", &d);
    c[0] = d[0];
    c[3] = d[1];
    scanf("%s", &d);
    c[1] = d[0];
    c[2] = d[1];
    scanf("%s", &d);
    bool found = false;
    for (int j = 0; j < cc.size(); j++) {
      for (int k = 0; k < 4; k++) {
        if (cc[j].compare(c) == 0) {
          found = true;
          break;
        } else {
          char t = c[0];
          c[0] = c[1];
          c[1] = c[2];
          c[2] = c[3];
          c[3] = t;
        }
      }
      if (found) {
        break;
      }
    }
    if (!found) {
      cc.push_back(c);
    }
  }
  printf("%d\n", cc.size());
  return 0;
}
