#include <bits/stdc++.h>
using namespace std;
string conv(string s) {
  string begin = "";
  string str[4] = {
      begin + s[0] + s[1] + s[2] + s[3], begin + s[1] + s[2] + s[3] + s[0],
      begin + s[2] + s[3] + s[0] + s[1], begin + s[3] + s[0] + s[1] + s[2]};
  return *min_element(str, str + 4);
}
int main() {
  set<string> p;
  int n;
  string s1, s2;
  cin >> n;
  while (n--) {
    cin >> s1 >> s2;
    reverse(s2.begin(), s2.end());
    p.insert(conv(s1 + s2));
    cin >> s1;
  }
  cout << p.size();
  return 0;
}
