Go Go Go Special Action Force!
Time limit3sMemory limit512 MB
Given a 9x9 grid of position codes, check whether each of the three groupings (columns, rows, and 3x3 blocks) contains all nine distinct codes.
- Level
Medium4 of 10
- Topics
- Implementation, Matrix, Simulation, Hash map
- Solved
- No attempts yet
Problem
You lead a special action force of 81 trained personnel. The force advances on the enemy in a formation. To attack, the force breaks into 9 companies of 9 personnel, and the 9 personnel of one company must hold 9 different positions. The positions are:
- Officer (O)
- Warrant Officer (WO)
- Weapons Sergeant (WS)
- Engineer Sergeant (ES)
- Medical Sergeant (MS)
- Communication Sergeant (CS)
- Intelligence Sergeant (IS)
- Operations Sergeant (OS)
- Senior Sergeant (SS)
There are 3 attack strategies: infiltrate, flanking maneuver and deploy.
In infiltrate, the personnel at the front take the lead. Each column of the formation advances in single file as one company, so the 9 columns are the 9 companies, and they set up 9 strategic posts behind enemy lines.
In flanking maneuver, the rows of the formation peel off alternately to the left and to the right and attack from the sides. The 9 rows are the 9 companies. The left flank always takes 4 companies and the right flank takes 5.
In deploy, the formation splits into 9 blocks of . The center block becomes the headquarters and the other 8 blocks become satellite posts, so the 9 blocks are the 9 companies.
A strategy is available only when every company it forms holds all 9 positions. Given a formation, decide whether all 3 strategies are available.
Input
The first line contains one integer , the number of forces.
Each force is given as 9 lines. Each line holds 9 position codes separated by single spaces.
Constraints:
- Every code in the input is one of the 9 position codes listed above.
Output
For each force, print one line. Print all 3 when the formation allows all 3 attack strategies, and not when it does not.


