#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, cnt = 1, k = 0;
  cin >> n;
  string A[n];
  for (int i = 0; i < 3 * n - 1; i++) {
    string s;
    cin >> s;
    if (s[0] == '*')
      cnt = 0;
    else {
      if (cnt == 1)
        A[k] = s;
      else {
        reverse(s.begin(), s.end());
        A[k] = A[k] + s;
        k++;
      }
    }
    cnt++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (A[i] != "-1") {
      for (int j = i + 1; j < n; j++) {
        string temp = A[j] + A[j];
        for (int k = 0; k < 4; k++) {
          string check;
          for (int k1 = 0; k1 < 4; k1++) {
            check.push_back(temp[k + k1]);
          }
          if (check == A[i]) {
            A[j] = "-1";
            break;
          }
        }
      }
      A[i] = "-1";
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
