#include <bits/stdc++.h>
using namespace std;
struct Amulet {
  int value;
  Amulet(int v) : value(v) {}
  static int rotate(int v) {
    static const int t[4] = {10, 1000, 1, 100};
    int ans = 0;
    for (int i = 0; i < 4; ++i, v /= 10) ans += t[i] * (v % 10);
    return ans;
  }
  bool operator==(const Amulet &other) {
    int v = value;
    for (int i = 0; i < 4; ++i) {
      if (v == other.value) return true;
      v = rotate(v);
    }
    return false;
  }
};
vector<Amulet> buffer;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  while (n-- > 0) {
    int a, b;
    cin >> a >> b;
    Amulet amulet(a * 100 + b);
    if (find(buffer.begin(), buffer.end(), amulet) == buffer.end())
      buffer.push_back(amulet);
    try {
      string tmp;
      cin >> tmp;
    } catch (...) {
    }
  }
  cout << buffer.size() << endl;
  return 0;
}
