#include <bits/stdc++.h>
using namespace std;
long long int n;
string upper, lower, f;
set<string> piles;
string rotateAmulet(string s) {
  char temp = s[3];
  for (long long int i = 0; i < 4; ++i) {
    long long int temp2 = s[i];
    s[i] = temp;
    temp = temp2;
  }
  return s;
}
int main() {
  scanf("%lld", &n);
  while (n--) {
    cin >> upper >> lower >> f;
    reverse(lower.begin(), lower.end());
    string s = upper + lower;
    bool flag = false;
    for (long long int i = 0; i < 4; ++i) {
      s = rotateAmulet(s);
      if (piles.count(s)) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      piles.insert(s);
    }
  }
  printf("%lld\n", (long long int)piles.size());
  return 0;
}
