#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  set<vector<int> > S;
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;
    vector<int> v;
    v.push_back(a[0]);
    v.push_back(a[1]);
    v.push_back(b[1]);
    v.push_back(b[0]);
    vector<int> Min = v;
    for (int i = 0; i < 4; i++) {
      int t = *v.begin();
      v.erase(v.begin());
      v.push_back(t);
      Min = min(Min, v);
    }
    S.insert(Min);
    cin >> a;
  }
  cout << S.size() << endl;
}
