#include <stdio.h>
#include <string.h>

int main()
{
	int i0, i1, i2, i3, n, m, d[30][6], s[30], sw;
	char c[8];
	char color[6][8] = {"Cyan", "Yellow", "Red", "Magenta", "Green", "Blue"};

	scanf("%d", &n);
	while (n > 0) {
		for (i0 = 0; i0 < n; i0++) {
			for (i1 = 0; i1 < 6; i1++) {
				scanf("%s", c);
				for (i2 = 0; i2 < 6; i2++) {
					if (strcmp(c, color[i2]) == 0) {
						d[i0][i1] = i2;
						break;
					}
				}
			}
		}
		m = 0;
		for (i0 = 0; i0 < n; i0++)
			s[i0] = 1;
		for (i0 = 0; i0 < n; i0++) {
			if (s[i0] > 0) {
				m++;
				s[i0] = 0;
				for (i1 = i0+1; i1 < n; i1++) {
					sw = 0;
					for (i2 = 0; i2 < 3 && sw == 0; i2++) {
						for (i3 = 0; i3 < 6 && sw == 0; i3++) {
							if (d[i0][i2] == d[i1][i3]) {
								if (d[i0][5-i2] != d[i1][5-i3])
									sw = 1;
							}
						}
					}
					if (sw == 0)
						s[i1] = 0;
				}
			}
		}
		printf("%d\n", n-m);
		scanf("%d", &n);
	}

	return 0;
}