#include <bits/stdc++.h>
using namespace std;
char sq[1010][2][2];
char temp[2][2];
bool same[1010][1010];
char s[4];
bool mark[1010];
int n;
void read(int idx) {
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) cin >> sq[idx][i][j];
}
bool isSame(int a, int b) {
  for (int rot = 0; rot < 4; rot++) {
    bool ret = true;
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++)
        if (sq[a][i][j] != sq[b][i][j]) ret = false;
    if (ret) return true;
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++) temp[i][j] = sq[a][j][2 - i - 1];
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++) sq[a][i][j] = temp[i][j];
  }
  return false;
}
void dfs(int idx) {
  mark[idx] = true;
  for (int i = 0; i < n; i++)
    if (!mark[i] && same[idx][i]) dfs(i);
}
int main() {
  cin >> n;
  read(0);
  for (int i = 1; i < n; i++) {
    cin >> s;
    read(i);
  }
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) same[i][j] = same[j][i] = isSame(i, j);
  int ret = 0;
  for (int i = 0; i < n; i++)
    if (!mark[i]) {
      ret++;
      dfs(i);
    }
  cout << ret << endl;
  return 0;
}
