#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, res;
vector<vector<char>> v;
char a[5];
void ok(vector<char> &x) {
  vector<char> temp2(4), temp3(4), temp4(4);
  if (find(v.begin(), v.end(), x) != v.end()) return;
  temp2[0] = x[2], temp2[1] = x[0], temp2[2] = x[3], temp2[3] = x[1];
  if (find(v.begin(), v.end(), temp2) != v.end()) return;
  temp3[0] = x[3], temp3[1] = x[2], temp3[2] = x[1], temp3[3] = x[0];
  if (find(v.begin(), v.end(), temp3) != v.end()) return;
  temp4[0] = x[1], temp4[1] = x[3], temp4[2] = x[0], temp4[3] = x[2];
  if (find(v.begin(), v.end(), temp4) != v.end()) return;
  ++res;
  v.push_back(x);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    if (i) scanf(" %s", a);
    vector<char> temp(4);
    scanf(" %s", a);
    temp[0] = a[0], temp[1] = a[1];
    scanf(" %s", a);
    temp[2] = a[0], temp[3] = a[1];
    ok(temp);
  }
  printf("%d", res);
  return 0;
}
