#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
class domino {
 public:
  int data[4];
  bool IsEqual(domino b) {
    for (long long move = 0; move <= 3; move++) {
      bool f = true;
      for (long long i = 0; i <= 3; i++)
        if (data[i] != b.data[(i + move) % 4]) f = false;
      if (f) return true;
    }
    return false;
  }
};
vector<domino> a;
int main() {
  int n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    domino temp;
    string s;
    cin >> s;
    temp.data[0] = s[0] - '0';
    temp.data[1] = s[1] - '0';
    cin >> s;
    temp.data[3] = s[0] - '0';
    temp.data[2] = s[1] - '0';
    bool f = true;
    if (a.size() == 0) a.push_back(temp);
    for (long long k = 0; k <= a.size() - 1; k++)
      if (temp.IsEqual(a[k])) f = false;
    if (f) a.push_back(temp);
    if (i != n) cin >> s;
  }
  cout << a.size();
}
