#include <bits/stdc++.h>
using namespace std;
int n, m;
set<string> s;
int main() {
  string a, b, c, d;
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      if (i != 0) cin >> a;
      cin >> a >> b;
      reverse(b.begin(), b.end());
      c = a + b + a + b;
      d = a + b;
      for (int j = 0; j < 4; j++) {
        d = min(d, c.substr(j, 4));
      }
      s.insert(d);
    }
    printf("%d\n", s.size());
  }
  return 0;
}
