#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  char s[3][3];
  while (scanf("%d", &n) == 1) {
    set<vector<int> > svi;
    int cnt = 0;
    for (i = 0; i < n; i++) {
      if (i) scanf("%s", s[0]);
      scanf("%s%s", s[0], s[1]);
      int a = s[0][0] - '0', b = s[0][1] - '0', c = s[1][0] - '0',
          d = s[1][1] - '0';
      vector<int> now;
      now.push_back(b);
      now.push_back(a);
      now.push_back(c);
      now.push_back(d);
      if (svi.find(now) == svi.end()) {
        cnt++;
        svi.insert(now);
        now.clear();
        now.push_back(d);
        now.push_back(b);
        now.push_back(a);
        now.push_back(c);
        svi.insert(now);
        now.clear();
        now.push_back(c);
        now.push_back(d);
        now.push_back(b);
        now.push_back(a);
        svi.insert(now);
        now.clear();
        now.push_back(a);
        now.push_back(c);
        now.push_back(d);
        now.push_back(b);
        svi.insert(now);
      }
    }
    printf("%d", cnt);
  }
  return 0;
}
