#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
map<int, int>::iterator it;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int atas, bawah;
    scanf("%d", &atas);
    scanf("%d", &bawah);
    if (i != n - 1) {
      getchar();
      getchar();
      getchar();
    }
    int a, b, c, d;
    a = atas / 10;
    b = atas % 10;
    c = bawah / 10;
    d = bawah % 10;
    int jenis[5];
    jenis[0] = a * 1000 + b * 100 + d * 10 + c;
    jenis[1] = b * 1000 + d * 100 + c * 10 + a;
    jenis[2] = d * 1000 + c * 100 + a * 10 + b;
    jenis[3] = c * 1000 + a * 100 + b * 10 + d;
    for (int i = 0; i < 4; i++) {
      it = m.find(jenis[i]);
      if (it != m.end()) break;
    }
    if (it == m.end()) {
      m[jenis[0]] += 1;
    } else {
      it->second += 1;
    }
  }
  printf("%d\n", m.size());
}
