#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int main() {
	int a, b[101][101] = { 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;
				}
			}
		}
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= 6; j++) {
				cout << b[i][j] << ",";
			}
			cout << endl;
		}

		int tatuo = 0;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= a; j++) {
				if (j != i && b[j][1] != -1 &&b[i][1]!=-1) {
					if (b[i][1] + b[i][6] == b[j][1] + b[j][6]) {
						if (b[i][3] + b[i][4] == b[j][3] + b[j][4]) {
							if (b[i][2] + b[i][5] == b[j][2] + b[j][5]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
							if (tatuo > 0)break;
						}
						if (tatuo > 0)break;
					}
					else if (b[i][1] + b[i][6] == b[j][3] + b[j][4]) {
						if (b[i][3] + b[i][4] == b[j][2] + b[j][5]) {
							if (b[i][2] + b[i][5] == b[j][1] + b[j][6]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
							if (tatuo > 0)break;
						}
						if (tatuo > 0)break;
					}
					else if (b[i][1] + b[i][6] == b[j][2] + b[j][5]) {
						if (b[i][3] + b[i][4] == b[j][1] + b[j][6]) {
							if (b[i][2] + b[i][5] == b[j][3] + b[j][4]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
							if (tatuo > 0)break;
						}
						if (tatuo > 0)break;
					}
					if (tatuo > 0) break;
				}
				if (tatuo > 0) {
					tatuo = 0;
					break;
				}
			}
		}
		cout << a-ruio << endl;
	}
}