Problems
Guardian of Decency
Guardian of Decency
Frank N. Stein is a very conservative high-school teacher. He wants to take some of his students on an excursion, but he is afraid that some of them might become couples. While you can never exclude this possibility, he has made some rules that he thinks indicates a low probability two persons will become a couple:
\begin{itemize}
\item Their height differs by more than \textbf{40} cm.
\item They are of the same sex.
\item Their preferred music style is different.
\item Their favourite sport is the same (they are likely to be fans of different teams and that would result in fighting).
\end{itemize}
So, for any two persons that he brings on the excursion, they must satisfy at least one of the requirements above. Help him find the maximum number of persons he can take, given their vital information.
\InputFile
The first line of the input consists of an integer \textbf{T} ≤ \textbf{100} giving the number of test cases. The first line of each test case consists of an integer \textbf{N} ≤ \textbf{500} giving the number of pupils. Next there will be one line for each pupil consisting of four space-separated data items:
\begin{itemize}
\item an integer \textbf{h} giving the height in cm;
\item a character '\textbf{F}' for female or '\textbf{M}' for male;
\item a string describing the preferred music style;
\item a string with the name of the favourite sport.
\end{itemize}
No string in the input will contain more than \textbf{100} characters, nor will any string contain any whitespace.
\OutputFile
For each test case in the input there should be one line with an integer giving the maximum number of eligible pupils.
Input example #1
1 8 27 M romance programming 194 F baroque programming 67 M baroque ping-pong 51 M classicism programming 80 M classicism Paintball 35 M baroque ping-pong 39 F romance ping-pong 110 M romance Paintball
Output example #1
7