#include <bits/stdc++.h>
using namespace std;
int n;
int d[8];
int s[9999];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    d[0] = t / 10;
    d[1] = t % 10;
    cin >> t;
    d[2] = t % 10;
    d[3] = t / 10;
    int t1 = d[0] * 1000 + d[1] * 100 + d[2] * 10 + d[3];
    int t2 = d[1] * 1000 + d[2] * 100 + d[3] * 10 + d[0];
    int t3 = d[2] * 1000 + d[3] * 100 + d[0] * 10 + d[1];
    int t4 = d[3] * 1000 + d[0] * 100 + d[1] * 10 + d[2];
    s[min(min(t1, t2), min(t3, t4))]++;
    if (i < n - 1) {
      string line;
      cin >> line;
    }
  }
  int k = 0;
  for (int i = 0; i <= 9999; ++i)
    if (s[i]) {
      ++k;
    }
  cout << k << endl;
}
