#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, j, k = 0, sm, x;
  string s;
  int ans = 0, y, tmp;
  bool fnd;
  int a[1001][5], tm[4];
  scanf("%d", &t);
  while (t--) {
    sm = 0;
    scanf("%d%d", &x, &y);
    tm[0] = x / 10;
    tm[1] = x % 10;
    tm[2] = y % 10;
    tm[3] = y / 10;
    sm = tm[0] + tm[1] + tm[2] + tm[3];
    fnd = false;
    for (i = 0; i < k; i++) {
      x = 1;
      if (sm == a[i][0]) {
        for (j = 0; j < 4; j++) {
          if (a[i][1] == tm[j]) {
            y = j;
            for (x = 1; x < 5; x++) {
              if (a[i][x] != tm[y]) break;
              y = (y + 1) % 4;
            }
          }
          if (x == 5) {
            ans++;
            fnd = true;
            break;
          }
        }
      }
      if (fnd) break;
    }
    if (!fnd) {
      for (j = 0; j < 4; j++) a[k][j + 1] = tm[j];
      a[k][0] = sm;
      k++;
    }
    if (t) cin >> s;
  }
  printf("%d\n", k);
  return 0;
}
