#include <bits/stdc++.h>
using namespace std;
vector<string> v;
int main() {
  string x, y;
  int cnt = 0;
  char temp;
  int n;
  cin >> n;
  n = n + n - 1;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == "**") continue;
    cin >> y;
    x += y;
    sort(v.begin(), v.end());
    if (binary_search(v.begin(), v.end(), x)) continue;
    cnt++;
    v.push_back(x);
    for (int j = 1; j <= 3; j++) {
      y = "";
      if (j == 1) {
        y += x[2];
        y += x[0];
        y += x[3];
        y += x[1];
        v.push_back(y);
      } else if (j == 2) {
        y += x[3];
        y += x[2];
        y += x[1];
        y += x[0];
        v.push_back(y);
      } else if (j == 3) {
        y += x[1];
        y += x[3];
        y += x[0];
        y += x[2];
        v.push_back(y);
      }
    }
  }
  cout << cnt;
  return 0;
}
