#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  vector<vector<vector<int> > > in(n);
  for (int i = (0); i < (n); i += 1) {
    vector<int> x(4);
    scanf("%1d%1d%1d%1d", &x[0], &x[1], &x[2], &x[3]);
    in[i].push_back(x);
    vector<int> v;
    v.clear();
    v.push_back(x[2]);
    v.push_back(x[0]);
    v.push_back(x[3]);
    v.push_back(x[1]);
    in[i].push_back(v);
    v.clear();
    v.push_back(x[3]);
    v.push_back(x[2]);
    v.push_back(x[1]);
    v.push_back(x[0]);
    in[i].push_back(v);
    v.clear();
    v.push_back(x[1]);
    v.push_back(x[3]);
    v.push_back(x[0]);
    v.push_back(x[2]);
    in[i].push_back(v);
    if (i + 1 != n) cin >> s;
  }
  int ad = 0;
  for (int i = (0); i < (n); i += 1) {
    bool ki = 0;
    for (int j = (0); j < (i); j += 1)
      for (int x = (0); x < (4); x += 1)
        for (int y = (0); y < (4); y += 1) ki |= in[i][x] == in[j][y];
    ad += !ki;
  }
  cout << ad << endl;
  return 0;
}
