#include <bits/stdc++.h>
using namespace std;
struct Node {
  string a;
  Node() { a.resize(4); }
  bool operator<(const Node& other) const { return a < other.a; }
  Node rotate() {
    Node ret = *this;
    ret.a[1] = a[0];
    ret.a[3] = a[1];
    ret.a[2] = a[3];
    ret.a[0] = a[2];
    return ret;
  }
};
set<Node> nodes;
void init() {
  int N;
  scanf("%d", &N);
  int ans = 0;
  string line;
  for (int i = 0; i < N; ++i) {
    Node now;
    getline(cin, line);
    getline(cin, line);
    now.a[0] = line[0];
    now.a[1] = line[1];
    getline(cin, line);
    now.a[2] = line[0];
    now.a[3] = line[1];
    if (nodes.find(now) == nodes.end()) ans++;
    nodes.insert(now);
    Node r1 = now.rotate();
    nodes.insert(r1);
    r1 = r1.rotate();
    nodes.insert(r1);
    r1 = r1.rotate();
    nodes.insert(r1);
  }
  cout << ans << endl;
}
void york() {}
int main() {
  init();
  york();
  return 0;
}
