#include <bits/stdc++.h>
using namespace std;
string arrange(string s) {
  string temp = s;
  for (int i = 0; i < 4; i++) {
    s = s.substr(1) + s[0];
    temp = min(temp, s);
  }
  return temp;
}
int main() {
  int n;
  scanf("%d", &n);
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    string s[2];
    cin >> s[0] >> s[1];
    a[i] = arrange(s[0] + s[1][1] + s[1][0]);
    if (i + 1 != n) cin >> s[0];
  }
  sort(a.begin(), a.end());
  printf("%d", int(unique(a.begin(), a.end()) - a.begin()));
  printf("\n");
}
