#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<deque<int>> piles;
  for (int i = 0; i < n; ++i) {
    deque<int> vi;
    int tmp = 0;
    cin >> tmp;
    int b = tmp % 10;
    tmp /= 10;
    int a = tmp % 10;
    vi.push_back(a);
    vi.push_back(b);
    cin >> tmp;
    vi.push_back(tmp % 10);
    tmp /= 10;
    vi.push_back(tmp % 10);
    if (piles.empty())
      piles.push_back(vi);
    else {
      bool flag = false;
      for (int j = 0; j < piles.size(); ++j) {
        deque<int> pile = piles[j];
        int k = 0;
        for (; k < 4; ++k) {
          if (pile == vi) break;
          int t = vi[0];
          vi.pop_front();
          vi.push_back(t);
        }
        if (k != 4) {
          flag = true;
          break;
        }
      }
      if (!flag) piles.push_back(vi);
    }
    string s;
    if (i != n - 1) cin >> s;
  }
  cout << piles.size() << endl;
  return 0;
}
