#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<char> LT, RT, LB, RB;
  int count = n;
  for (int i = 0; i < n; i++) {
    char a, b, c, d;
    string s;
    cin >> a >> b >> c >> d;
    if (i != n - 1) cin >> s;
    bool is = false;
    for (int i = 0; i < LT.size(); i++) {
      if (a == LT[i] && b == RT[i] && c == LB[i] && d == RB[i]) is = true;
      if (b == LT[i] && d == RT[i] && a == LB[i] && c == RB[i]) is = true;
      if (d == LT[i] && c == RT[i] && b == LB[i] && a == RB[i]) is = true;
      if (c == LT[i] && a == RT[i] && d == LB[i] && b == RB[i]) is = true;
    }
    if (is)
      count--;
    else {
      LT.push_back(a);
      RT.push_back(b);
      LB.push_back(c);
      RB.push_back(d);
    }
  }
  cout << count << endl;
  return 0;
}
