#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=5+3*1e+4;
const ut INF=1<<30;
const ld eps=1e-6;
const LL p=7+1e+9;

map<string, int> colors;
int main(){
	int n;
	colors["Red"] = 0;
	colors["Magenta"] = 1;
	colors["Blue"] = 2;
	colors["Green"] = 3;
	colors["Yellow"] = 4;
	colors["Cyan"] = 5;
	
	while(cin >> n && n){
		vector<Vpr> vec;
		int ans = 0;
		REP(i,n){
			string s[6];
			REP(j,6){
				cin >> s[j];
			}
			Vpr tmp;
			REP(j,3){
				tmp.PB(pr(min(colors[s[j]], colors[s[6 - j - 1]]), max(colors[s[j]], colors[s[6 - j - 1]])));
			}
			sort(BE(tmp));
			bool H = false;
			REP(j,vec.size()){
				bool ok = true;
				REP(k,3){
					if(!(vec[j][k].F == tmp[k].F && vec[j][k].S == tmp[k].S)){
						ok = false;
						break;
					}
				}
				if(ok){
					H = true;
					break;
				}
			}
			if(H){
				ans++;
			}
			else{
				vec.PB(tmp);
			}
		}
		cout << ans << endl;
	}
}