Under construction

Still being built. Things may change

Go Go Go Special Action Force!

Time limit3sMemory limit512 MB

Summary
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 9×99 \times 9 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 3×33 \times 3. The center block becomes the headquarters and the other 8 blocks become satellite posts, so the 9 blocks are the 9 companies.

Figure 1: InfiltrateFigure 2: Flanking maneuverFigure 3: Deploy

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 GG, the number of forces.

Each force is given as 9 lines. Each line holds 9 position codes separated by single spaces.

Constraints:

  • 1≤G≤3501 \le G \le 350
  • 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.

Examples2

  1. Example 1

    Input
    2
    OS MS IS O WS CS SS ES WO
    SS WO CS OS ES MS O IS WS
    O ES WS SS IS WO MS OS CS
    IS O WO MS CS ES OS WS SS
    CS WS OS IS WO SS ES O MS
    MS SS ES WS OS O WO CS IS
    ES IS SS WO O WS CS MS OS
    WS CS MS ES SS OS IS WO O
    WO OS O CS MS IS WS SS ES
    CS OS ES MS IS O WS WO SS
    MS SS WS WO ES OS CS IS O
    IS O WO SS WS MS OS ES MS
    O WO OS WS CS IS MS SS ES
    ES CS SS O OS MS IS WS WO
    WS MS IS ES SS WO O OS CS
    SS IS O CS WO WS ES MS OS
    WO WS MS OS O ES SS CS IS
    OS ES CS IS MS SS WO O WS
    
    Expected output
    all 3
    not
    
  2. Example 2

    Input
    1
    O WO WS ES MS CS IS OS SS
    ES MS CS IS OS SS O WO WS
    IS OS SS O WO WS ES MS CS
    WO WS ES MS CS IS OS SS O
    MS CS IS OS SS O WO WS ES
    OS SS O WO WS ES MS CS IS
    WS ES MS CS IS OS SS O WO
    CS IS OS SS O WO WS ES MS
    SS O WO WS ES MS CS IS OS
    
    Expected output
    all 3