#include <bits/stdc++.h>
double const PI = 4 * atan(1.0);
using namespace std;
string s[3];
int a[1111][8], n;
bool giongnhau(int u, int v) {
  for (int i = 0; i <= 3; i++) {
    bool check = true;
    for (int j = 0; j < 4; j++)
      if (a[u][j] != a[v][j + i]) {
        check = false;
        break;
      }
    if (check) return true;
  }
  return false;
}
int main() {
  int kq = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    if (i == n - 1)
      cin >> s[0] >> s[1];
    else
      cin >> s[0] >> s[1] >> s[2];
    a[i][0] = s[0][0] - '0';
    a[i][4] = a[i][0];
    a[i][1] = s[0][1] - '0';
    a[i][5] = a[i][1];
    a[i][2] = s[1][1] - '0';
    a[i][6] = a[i][2];
    a[i][3] = s[1][0] - '0';
    a[i][7] = a[i][3];
    bool check = false;
    for (int j = 0; j < i; j++)
      if (giongnhau(i, j)) {
        check = true;
        break;
      }
    if (!check) kq++;
  }
  cout << kq;
}
