#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
int toInt(char xx) { return xx - '0'; }
char toChar(int xx) { return xx + '0'; }
bool isNum(char xx) { return ('0' <= xx && xx <= '9'); }
int n;
string x, y, tmp;
vector<set<string> > vss;
vector<string> quay(string a) {
  vector<string> res;
  for (int startPoint = 0; startPoint <= 3; ++startPoint) {
    tmp = "";
    int id = startPoint;
    tmp.push_back(a[id]);
    id = (id + 1) % 4;
    tmp.push_back(a[id]);
    id = (id + 1) % 4;
    tmp.push_back(a[id]);
    id = (id + 1) % 4;
    tmp.push_back(a[id]);
    res.push_back(tmp);
  }
  return res;
}
void read() {
  cin >> n;
  for (int p = 1; p <= n; ++p) {
    cin >> x >> y;
    x.push_back(y[1]);
    x.push_back(y[0]);
    vector<string> rs = quay(x);
    bool addTo = true;
    for (int i = 0; i < (int)vss.size(); ++i) {
      if (!addTo) {
        break;
      }
      for (int j = 0; j < (int)rs.size(); ++j) {
        if (vss[i].count(rs[j]) > 0) {
          addTo = false;
          break;
        }
      }
    }
    if (addTo) {
      set<string> ss;
      for (int j = 0; j < (int)rs.size(); ++j) {
        ss.insert(rs[j]);
      }
      vss.push_back(ss);
    }
    cin >> tmp;
  }
}
void init() { cout << vss.size(); }
void solve() {}
int main() {
  read();
  init();
  solve();
}
