#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int main() {
	int a, b[101][101],kotaneet=0,ruio=0;
	char str[101];
	while (1) {
		cin >> a;
		if (a == 0)return 0;
		ruio = a;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= 6; j++) {
				scanf("%s", str);
				if (strstr(str, "Red") != NULL) {
					b[i][j] = 1;
				}
				if (strstr(str, "Yellow") != NULL) {
					b[i][j] = 2;
				}
				if (strstr(str, "Blue") != NULL) {
					b[i][j] = 3;
				}
				if (strstr(str, "Magenta") != NULL) {
					b[i][j] = 4;
				}
				if (strstr(str, "Green") != NULL) {
					b[i][j] = 5;
				}
				if (strstr(str, "Cyan") != NULL) {
					b[i][j] = 6;
				}
			}
		}
		kotaneet = 0;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= a; j++) {
				if (j != i && b[j][1] != -1) {
					//cout << "tatuya0" << endl;
					if (b[i][1] + b[i][6] == b[j][1] + b[j][6]) {
						//cout << "tatuya1" << endl;
						if (b[i][3] + b[i][4] == b[j][3] + b[j][4]) {
							//cout << "tatuya2" << endl;
							if (b[i][2] + b[i][5] == b[j][2] + b[j][5]) {
								//cout << "tatuya3" << endl;
								kotaneet++;
								b[i][1] = -1;
								ruio--;
								break;
							}
						}
					}
				}
			}
		}
		cout << a-ruio << endl;
	}
}