#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;
void run() {
  int n, ans = 0;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    string a, b, c;
    cin >> a >> b;
    if (i < n - 1) cin >> c;
    int d[2][2], e[2][2];
    for (int i = 0; i < 2; i++) {
      d[0][i] = a[i] - '0';
      d[1][i] = b[i] - '0';
    }
    bool ok = 1;
    for (int i = 0; i < 4; i++) {
      int enc = d[0][0] + d[0][1] * 7 + d[1][0] * 7 * 7 + d[1][1] * 7 * 7 * 7;
      if (!s.count(enc)) ok = 0;
      s.insert(enc);
      e[0][0] = d[0][1];
      e[0][1] = d[1][1];
      e[1][1] = d[1][0];
      e[1][0] = d[0][0];
      for (int x = 0; x < 2; x++)
        for (int y = 0; y < 2; y++) d[x][y] = e[x][y];
    }
    if (!ok) ans++;
  }
  cout << ans << endl;
}
int main() { run(); }
