#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, input[4], line[4];
  int dx[] = {0, 1, 3, 2};
  char charactor;
  vector<int> answer;
  answer.clear();
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      cin >> charactor;
      input[j] = charactor - '0';
    }
    for (int start = 0; start < 4; start++) {
      line[start] = 0;
      for (int temp = 0; temp < 4; temp++) {
        line[start] *= 10;
        line[start] += input[dx[(start + temp) % 4]];
      }
    }
    int count = answer.size();
    for (int j = 0; j < count; j++) {
      for (int k = 0; k < 4; k++) {
        if (answer[j] == line[k]) goto NEXT;
      }
    }
    answer.push_back(line[0]);
  NEXT:;
    if (i == n - 1) break;
    for (int j = 0; j < 2; j++) cin >> charactor;
  }
  cout << answer.size() << endl;
  return 0;
}
