#include <bits/stdc++.h>
using namespace std;
set<string> st;
int tab[4][4] = {{1, 2, 3, 4}, {2, 4, 1, 3}, {4, 3, 2, 1}, {3, 1, 4, 2}};
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int w = 0;
  string s, s1, t[3];
  for (int i = 0; i <= (int)(n)-1; i++) {
    for (int j = 0; j <= (int)(3) - 1; j++) cin >> t[j];
    s = t[0] + t[1];
    if (!((st).find((s)) != (st).end())) {
      w++;
      s1 = s;
      for (int j = 0; j <= (int)(4) - 1; j++) {
        for (int k = 0; k <= (int)(4) - 1; k++) s1[k] = s[tab[j][k] - 1];
        st.insert(s1);
      }
    }
  }
  cout << w;
  return 0;
}
