#include <bits/stdc++.h>
using namespace std;
int n;
set<string> s1, s2, s3;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;
    a += b;
    if (i < n - 1) cin >> b;
    string c[5];
    for (int j = 0; j < 4; j++) {
      c[j] = a;
      a = a[2] + a;
      a.erase(3, 1);
      swap(a[2], a[3]);
    }
    if (c[0] == c[1] && c[1] == c[2])
      s3.insert(c[0]);
    else if (c[0] == c[2] && c[1] == c[3]) {
      s2.insert(c[0]);
      s2.insert(c[1]);
    } else
      for (int j = 0; j < 4; j++) s1.insert(c[j]);
  }
  cout << s1.size() / 4 + s2.size() / 2 + s3.size();
  return 0;
}
