#include <bits/stdc++.h> using namespace std; vector<vector<string>> subvec(vector<vector<string>>a, int x){ vector<vector<string>>p; int t = x + 4; for(;x < t;x++)p.push_back(a[x]); return p; } map<vector<vector<string>>, int>m; bool check(vector<vector<string>>p){ if(m[p] > 1)return false; string a = p[0][0] + p[0][1] + p[0][2] + p[0][3]; string b = p[0][3] + p[1][3] + p[2][3] + p[3][3]; string c = p[3][3] + p[3][2] + p[3][1] + p[3][0]; string d = p[3][0] + p[2][0] + p[1][0] + p[0][0]; string e = p[0][0] + p[1][1] + p[2][2] + p[3][3]; string f = p[0][3] + p[1][2] + p[2][1] + p[3][0]; sort(a.begin(), a.end()); sort(b.begin(), b.end()); sort(c.begin(), c.end()); sort(d.begin(), d.end()); sort(e.begin(), e.end()); sort(f.begin(), f.end()); return (a != b && a != c && a != d && a != e && a != f && b != c && b != d && b != e && b != f && c != d && c != e && c != f && d != e && d != f && e != f); } int main(){ int n, sum = 0; cin >> n; vector<vector<string>>a(n, vector<string>(4)); for(int i = 0;i < n;i++){ for(int j = 0;j < 4;j++){ cin >> a[i][j]; } } for(int i = 0;i < n - 3;i += 4){ m[subvec(a, i)]++; if(check(subvec(a, i)))sum++; } cout << sum << endl; return 0; }