#include <bits/stdc++.h>
using namespace std;
int n, i, j, a, b, c, d, ans, x, y;
map<pair<pair<int, int>, pair<int, int> >, bool> mp;
pair<pair<int, int>, pair<int, int> > k1, k2, k3, k4;
int main() {
  scanf("%d", &n);
  ans = 0;
  mp.clear();
  for (i = 0; i < n; i++) {
    scanf("%d%d", &x, &y);
    a = x / 10;
    b = x % 10;
    c = y / 10;
    d = y % 10;
    getchar();
    if (i < n - 1) {
      getchar();
      getchar();
      getchar();
    }
    k1 = make_pair(make_pair(a, b), make_pair(c, d));
    k2 = make_pair(make_pair(c, a), make_pair(d, b));
    k3 = make_pair(make_pair(d, c), make_pair(b, a));
    k4 = make_pair(make_pair(b, d), make_pair(a, c));
    if (mp.count(k1) != 0 || mp.count(k2) != 0 || mp.count(k3) != 0 ||
        mp.count(k4) != 0)
      continue;
    else {
      mp[k1] = 1;
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
