#include <bits/stdc++.h>
using namespace std;
const int N = 25;
void solve(pair<string, string> ps, vector<set<pair<string, string> > > &v) {
  string s1 = ps.first;
  string s2 = ps.second;
  string s3 = "";
  s3 += s1[1];
  s3 += s2[1];
  string s4 = "";
  s4 += s1[0];
  s4 += s2[0];
  string s5 = "";
  s5 += s2[1];
  s5 += s2[0];
  string s6 = "";
  s6 += s1[1];
  s6 += s1[0];
  string s7 = "";
  s7 += s2[0];
  s7 += s1[0];
  string s8 = "";
  s8 += s2[1];
  s8 += s1[1];
  bool found = false;
  for (int i = (0), _b = (v.size()); i < (_b); ++i) {
    set<pair<string, string> > s = v[i];
    if (((s).find(make_pair(s1, s2)) != (s).end())) {
      found = true;
      break;
    }
  }
  if (!found) {
    set<pair<string, string> > s;
    s.insert(make_pair(s1, s2));
    s.insert(make_pair(s3, s4));
    s.insert(make_pair(s5, s6));
    s.insert(make_pair(s7, s8));
    v.push_back(s);
  }
}
int main() {
  int n;
  cin >> n;
  string s1, s2, s3;
  pair<string, string> a[n];
  vector<set<pair<string, string> > > v;
  for (int i = (0), _b = (n); i < (_b); ++i) {
    cin >> s1 >> s2 >> s3;
    a[i] = make_pair(s1, s2);
  }
  for (int i = (0), _b = (n); i < (_b); ++i) {
    solve(a[i], v);
  }
  int ret = v.size();
  cout << ret << endl;
  return 0;
}
