#include <bits/stdc++.h>
using namespace std;
int getVal(int a, int b, int c, int d) {
  int e = d - '0';
  e += (c - '0') * 10;
  e += (b - '0') * 100;
  e += (a - '0') * 1000;
  return e;
}
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  set<int> st;
  char a, b, c, d;
  int me, e;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b >> c >> d;
    e = getVal(a, b, d, c);
    me = e;
    e = getVal(b, d, c, a);
    me = min(e, me);
    e = getVal(d, c, a, b);
    me = min(e, me);
    e = getVal(c, a, b, d);
    me = min(e, me);
    st.insert(me);
    if (i != n - 1) cin >> a >> b;
  }
  cout << st.size() << endl;
}
