#include <bits/stdc++.h>
using namespace std;
bool cmp(const vector<int>& a, const vector<int>& b) {
  if (a[0] == b[0] && a[1] == b[1] && a[3] == b[3] && a[2] == b[2]) return true;
  if (a[0] == b[1] && a[1] == b[3] && a[3] == b[2] && a[2] == b[0]) return true;
  if (a[0] == b[3] && a[1] == b[2] && a[3] == b[0] && a[2] == b[1]) return true;
  if (a[0] == b[2] && a[1] == b[0] && a[3] == b[1] && a[2] == b[3]) return true;
  return false;
}
int main() {
  int n = ({
    int t;
    scanf("%d", &t);
    t;
  });
  vector<vector<int> > there;
  for (int i = 1; i <= n; i++) {
    vector<int> temp;
    bool f = true;
    string s;
    cin >> s;
    temp.push_back(s[0] - '0');
    temp.push_back(s[1] - '0');
    cin >> s;
    temp.push_back(s[0] - '0');
    temp.push_back(s[1] - '0');
    if (i != n) cin >> s;
    for (int i = 0; i < (int)there.size(); i++) {
      if (cmp(temp, there[i]) == true) {
        f = false;
        break;
      }
    }
    if (f) there.push_back(temp);
  }
  cout << (int)there.size() << endl;
  return 0;
}
